This paper describes a measurement of light-by-light scattering based onPb+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 and2018 at $\sqrt{s_\mathrm{NN}}=5.02$ TeV. Light-by-light scattering candidatesare selected in events with two photons produced exclusively, each withtransverse energy $E_{\mathrm{T}}^{\gamma} &gt; 2.5$ GeV, pseudorapidity$|\eta_{\gamma}| &lt; 2.37$, diphoton invariant mass $m_{\gamma\gamma} &gt; 5$ GeV,and with small diphoton transverse momentum and diphoton acoplanarity. Theintegrated and differential fiducial cross sections are measured and comparedwith theoretical predictions. The diphoton invariant mass distribution is usedto set limits on the production of axion-like particles. This result providesthe most stringent limits to date on axion-like particle production for massesin the range 6-100 GeV. Cross sections above 2 to 70 nb are excluded at the 95%CL in that mass interval.