Protecting quantum entanglement from leakage and qubit errors via repetitive parity measurements