Quantum communication is a method that offers efficient and secure ways for the exchange of information in a network. Large-scale quantum communication (of the order of 100 km) has been achieved; however, serious problems occur beyond this distance scale, mainly due to inevitable photon loss in the transmission channel. Quantum communication eventually fails when the probability of a dark count in the photon detectors becomes comparable to the probability that a photon is correctly detected. To overcome this problem, Briegel, D{u}r, Cirac and Zoller (BDCZ) introduced the concept of quantum repeaters, combining entanglement swapping and quantum memory to efficiently extend the achievable distances. Although entanglement swapping has been experimentally demonstrated, the implementation of BDCZ quantum repeaters has proved challenging owing to the difficulty of integrating a quantum memory. Here we realize entanglement swapping with storage and retrieval of light, a building block of the BDCZ quantum repeater. We follow a scheme that incorporates the strategy of BDCZ with atomic quantum memories. Two atomic ensembles, each originally entangled with a single emitted photon, are projected into an entangled state by performing a joint Bell state measurement on the two single photons after they have passed through a 300-m fibre-based communication channel. The entanglement is stored in the atomic ensembles and later verified by converting the atomic excitations into photons. Our method is intrinsically phase insensitive and establishes the essential element needed to realize quantum repeaters with stationary atomic qubits as quantum memories and flying photonic qubits as quantum messengers.