Quantum annealing (QA) and the quantum approximate optimization algorithm (QAOA) are two special cases of the following control problem: apply a combination of two Hamiltonians to minimize the energy of a quantum state. Which is more effective has remained unclear. Here we analytically apply the framework of optimal control theory to show that generically, given a fixed amount of time, the optimal procedure has the pulsed (or "bang-bang") structure of QAOA at the beginning and end but can have a smooth annealing structure in between. This is in contrast to previous works which have suggested that bang-bang (i.e., QAOA) protocols are ideal. To support this theoretical work, we carry out simulations of various transverse field Ising models, demonstrating that bang-anneal-bang protocols are more common. The general features identified here provide guideposts for the nascent experimental implementations of quantum optimization algorithms.