  The decays $B^+\rightarrow J/\psi \pi^+ \pi^- K^+$ are studied using a data
set corresponding to an integrated luminosity of 9fb$^{-1}$ collected with the
LHCb detector in proton-proton collisions between 2011 and 2018. Precise
measurements of the ratios of branching fractions with the intermediate
$\psi_2(3823)$, $\chi_{c1}(3872)$ and $\psi(2S)$ states are reported. The decay
of $B^+\rightarrow \psi_2(3823)K^+$ with $\psi_2(3823)\rightarrow
J\psi\pi^+\pi^-$ is observed for the first time with a significance of 5.1
standard deviations. The mass differences between the $\psi_2(3823)$,
$\chi_{c1}(3872)$ and $\psi(2S)$ states are measured to be $$
\begin{array}{rcl} m_{\chi_{c1(3872)}} - m_{\psi_2(3823)} &= & 47.50 \pm 0.53
\pm 0.13\,\mathrm{MeV/}c^2\,, \\ m_{\psi_2(3823)} - m_{\psi(2S)} &= & 137.98
\pm 0.53 \pm 0.14\,\mathrm{MeV/}c^2\,, \\ m_{\chi_{c1}(3872)} - m_{\psi(2S)} &=
& 185.49 \pm 0.06 \pm 0.03\,\mathrm{MeV/}c^2\,, \end{array} $$ resulting in the
most precise determination of the $\chi_{c1}(3782)$ mass. The width of the
$\psi_2(3823)$ state is found to be below 5.2MeV at 90\% confidence level. The
Breit-Wigner width of the $\chi_{c1}(3872)$ state is measured to be $$
\Gamma^{\mathrm{BW}}_{\chi_{c1}(3872)} = 0.96^{+0.19}_{-0.18}\pm0.21
\mathrm{MeV},$$ which is inconsistent with zero by 5.5 standard deviations.
