A fundamental requirement for enabling fault-tolerant quantum information processing is an efficient quantum error-correcting code that robustly protects the involved fragile quantum states from their environment. Just as classical error-correcting codes are indispensible in today's information technologies, it is believed that quantum error-correcting code will play a similarly crucial role in tomorrow's quantum information systems. Here, we report on the experimental demonstration of a quantum erasure-correcting code that overcomes the devastating effect of photon losses. Our quantum code is based on linear optics, and it protects a four-mode entangled mesoscopic state of light against erasures. We investigate two approaches for circumventing in-line losses, and demonstrate that both approaches exhibit transmission fidelities beyond what is possible by classical means. Because in-line attenuation is generally the strongest limitation to quantum communication, such an erasure-correcting code provides a new tool for establishing quantum optical coherence over longer distances.