This paper describes a measurement of light-by-light scattering based on Pb+Pb collision data recorded by the ATLAS experiment during Run 2 of the LHC. The study uses 2.2 nb(-1) of integrated luminosity collected in 2015 and 2018 at root sNN = 5.02TeV. Light-by-light scattering candidates are selected in events with two photons produced exclusively, each with transverse energy E-T(gamma) > 2.5 GeV, pseudorapidity vertical bar eta(gamma)vertical bar < 2.37, diphoton invariant mass m(gamma gamma) > 5 GeV, and with small diphoton transverse momentum and diphoton acoplanarity. The integrated and differential fiducial cross sections are measured and compared with theoretical predictions. The diphoton invariant mass distribution is used to set limits on the production of axion-like particles. This result provides the most stringent limits to date on axion-like particle production for masses in the range 6-100 GeV. Cross sections above 2 to 70 nb are excluded at the 95% CL in that mass interval.