We study theoretically quantum states of a pair of photons interacting with a finite periodic array of two-level atoms in a waveguide. Our calculation reveals two-polariton eigenstates that have a highly irregular wave-function in real space. This indicates the Bethe ansatz breakdown and the onset of quantum chaos, in stark contrast to the conventional integrable problem of two interacting bosons in a box. We identify the long-range waveguide-mediated coupling between the atoms as the key ingredient of chaos and nonintegrability. Our results provide new insights in the interplay between order, chaos and localization in many-body quantum systems and can be tested in state-of-the-art setups of waveguide quantum electrodynamics.