Oxynitrides have been explored extensively in the past decade because of their interesting properties, such as visible-light absorption, photocatalytic activity and high dielectric permittivity. Their synthesis typically requires high-temperature NH3 treatment (800–1,300 °C) of precursors, such as oxides, but the highly reducing conditions and the low mobility of N3− species in the lattice place significant constraints on the composition and structure—and hence the properties—of the resulting oxynitrides. Here we show a topochemical route that enables the preparation of an oxynitride at low temperatures (<500 °C), using a perovskite oxyhydride as a host. The lability of H− in BaTiO3−xHx (x ≤ 0.6) allows H−/N3− exchange to occur, and yields a room-temperature ferroelectric BaTiO3−xN2x/3. This anion exchange is accompanied by a metal-to-insulator crossover via mixed O–H–N intermediates. These findings suggest that this ‘labile hydride’ strategy can be used to explore various oxynitrides, and perhaps other mixed anionic compounds.