We show how to use optimal control theory to derive optimal time-consistent Markov-perfect government policies in nonlinear dynamic general equilibrium models, extending the result of Cohen and Michel (1988) for models with quadratic objective functions and linear dynamics. We replace private agents' costates by flexible functions of current states in the government's maximization problem. The functions are verified in equilibrium to an arbitrarily close degree of approximation. They can be found numerically by perturbation or projection methods. We use a stochastic model of optimal public spending to illustrate the technique.