This paper presents a generalized method of moments algorithm for estimating the structural parameters of a macroeconomic model subject to the restriction that the coefficients of the monetary policy rule minimize the central bank's expected loss function. The algorithm combines least-squares normal equations with moment restrictions derived from the first-order necessary conditions of the auxiliary optimization. We assess the performance of the algorithm with Monte Carlo simulations using three increasingly complex models. We find that imposing the optimizing restrictions when they are true improves estimation accuracy and that imposing those restrictions when they are false biases estimates of some of the structural parameters but not of the policy-rule coefficients.