We present a framework to accelerate optimization of problems where the objective function is governed by a nonlinear partial differential equation (PDE) using projection-based reduced-order models (ROMs) and a trust-region (TR) method. To reduce the cost of objective function evaluations by several orders of magnitude, we replace the underlying full-order model (FOM) with a series of hyperreduced ROMs (HROMs) constructed on-the-fly. Each HROM is equipped with an online-efficient a posteriori error estimator, which is used to define a TR. Hyperreduction is performed following a goal-oriented empirical quadrature procedure, which guarantees first-order consistency of the HROM with the FOM at the TR center. This ensures the optimizer converges to a local minimum of the underlying FOM problem. We demonstrate the framework through optimization of a nonlinear thermal fin and pressure-matching inverse design of an airfoil under Euler flow and Reynolds-averaged Navier-Stokes flow