Context. Neutron-capture elements represent an important nucleosynthetic channel in the study of the Galactic chemical evolution of stellar populations. For stellar populations behind significant extinction, such as those in the Galactic centre and along the Galactic plane, abundance analyses based on near-infrared (NIR) spectra are necessary. Previously, spectral lines from the neutron-capture elements, such as copper (Cu), cerium (Ce), neodymium (Nd), and ytterbium (Yb), have been identified in the H band, while yttrium (Y) lines have been identified in the K band. Aims. Due to the scarcity of spectral lines from neutron-capture elements in the NIR, the addition of useful spectral lines from other neutron-capture elements is highly desirable. The aim of this work is to identify and characterise a spectral line suitable for abundance determination from the most commonly used s-process element, namely barium. Methods. We observed the NIR spectra of 37 M giants in the solar neighbourhood at high spectral resolution and with a high signal-to-noise ratio using the IGRINS spectrometer on the GEMINI South telescope. The full H- and K-bands were recorded simultaneously at R = 45 000. Using a manual spectral synthesis method, we determined the fundamental stellar parameters for these stars and derived the barium abundance from the Ba line (6s5d 3D2 → 6s6p 3P2o) at λair = 23 253.56 Å in the K band. Results. We demonstrate that the Ba line in the K band at 2.33 μm (λ23 253.56) is useful for abundance analyses from the spectra of M giants. The line becomes progressively weaker at higher temperatures and is only useful in M giants and the coolest K giants at supersolar metallicities. Conclusions. We can now add Ba to the trends of the heavy elements Cu, Zn, Y, Ce, Nd, and Yb, which can be retrieved from high-resolution H- and K-band spectra. This opens up the study of nucleosynthetic channels, including the s-process and the r-process, in dust-obscured populations. Thus, these elements can be studied for heavily dust-obscured regions of the Galaxy, such as the Galactic centre.