  We present a detailed study of the internal structure and kinematics of the
core of the Sagittarius dwarf spheroidal galaxy (Sgr). Using machine-learning
techniques, we have combined the information provided by 3300 RR Lyrae stars,
more than 2000 spectroscopically observed stars, and the Gaia second data
release to derive the full phase space, i.e. 3D positions and kinematics, of
more than $1.2\times10^5$ member stars in the core of the galaxy. Our results
show that Sgr has a bar structure $\sim 2.5$ kpc long, and that tidal tails
emerge from its tips to form what it is known as the Sgr stream. The main body
of the galaxy, strongly sheared by tidal forces, is a triaxial (almost prolate)
ellipsoid with its longest principal axis of inertia inclined
$43^\circ\pm6^\circ$ with respect to the plane of the sky and axis ratios of
1:0.67:0.60. Its external regions are expanding mainly along its longest
principal axis, yet the galaxy conserves an inner core of about
$500\times330\times300$ pc that shows no net expansion and is rotating at
$v_{\rm rot} = 4.13 \pm 0.16$ ${\rm{ km \ s^{-1}}}$. The internal angular
momentum of Sgr forms an angle $\theta = 18^\circ\pm6^\circ$ with respect to
its orbital angular momentum, meaning that the galaxy is in an inclined
prograde orbit around the Milky Way. We compared our results with predictions
from $N$-body models with spherical, pressure-supported progenitors and a model
whose progenitor is a flattened rotating disk. Only the rotating model, based
on preexisting simulations aimed at reproducing the line-of-sight velocity
gradients observed in Sgr, was able to reproduce the observed properties in the
core of the galaxy.
