A sufficiency theorem for optimal control