A general proof of the quantum null energy condition