We show that every (graded) derivation on the algebra of free quantum fields and their Wick powers in curved spacetimes gives rise to a set of anomalous Ward identities for time-ordered products, with an explicit formula for their classical limit. We study these identities for the Koszul-Tate and the full BRST differential in the BV-BRST formulation of perturbatively interacting quantum gauge theories, and clarify the relation to previous results. In particular, we show that the quantum BRST differential, the quantum antibracket and the higher-order anomalies form an $L_\infty$ algebra. The defining relations of this algebra ensure that the gauge structure is well-defined on cohomology classes of the quantum BRST operator, i.e., observables. Furthermore, we show that one can determine contact terms such that also the interacting time-ordered products of multiple interacting fields are well defined on cohomology classes. An important technical improvement over previous treatments is the fact that all our relations hold off-shell and are independent of the concrete form of the Lagrangian, including the case of open gauge algebras.