This paper examines the stochastic maximum principle (SMP) for a forward–backward stochastic control system where the backward state equation is characterized by the backward stochastic differential equation (BSDE) with quadratic growth and the forward state at the terminal time is constrained in a convex set with probability one. With the help of the theory of BSDEs with quadratic growth and the bounded mean oscillation (BMO) martingales, we employ the terminal perturbation approach and Ekeland’s variational principle to obtain a dynamic stochastic maximum principle. The main result has a wide range of applications in mathematical finance and we investigate a robust recursive utility maximization problem with bankruptcy prohibition as an example.