The Europa League winners, who are signing the Tunisia international as part of their bid to avoid relegation from LaLiga, have an option to buy him in the summer for £14m plus a further £3m in add-ons.
As part of the terms of the deal, United have both a buyback option and a sell-on clause. United extended the 20-year-old’s contract by a year, until 2025, earlier this month to protect his value in the transfer market.
Hannibal has become the fourth player to leave Old Trafford in January, with Donny van de Beek and Jadon Sancho joining Eintracht Frankfurt and Borussia Dortmund respectively on loan and Sergio Reguilon sent back to Tottenham after his own loan spell in Manchester.
Left-back Alvaro Fernandez is expected to be sold to Benfica after being recalled from his loan in Spain with Granada.
Hannibal, who also attracted interest from Everton this month, has made 10 appearances for United this season, scoring his first goal for the club against Brighton and starting the Champions League defeat to Galatasaray.
But with Casemiro fit again and Mason Mount due to return soon, manager Erik ten Hag believes he has enough options in midfield without Hannibal, who United bought from Monaco in 2019.