Motivated by the fact that Bardeen black holes do not satisfy the usual first law and Smarr formula, we derive a generalized first law from the Lagrangian of nonlinear gauge field coupled to gravity. In our treatment, the Lagrangian is a function of the electromagnetic invariant as well as some additional parameters. Consequently, we obtain new terms in the first law. With our formula, we find the correct forms of the first law for Bardeen black holes and Born-Infeld black holes. By scaling arguments, we also derive a general Smarr formula from the first law. Our results apply to a wide class of black holes with nonlinear gauge fields. *