MADRID - Liverpool have agreed to sell Spain midfielder Xabi Alonso to Real Madrid, the two clubs announced on Tuesday. The 27-year-old, who had been with Liverpool for five seasons, will move for an undisclosed fee, subject to a medical, Liverpool said on their website. "Liverpool Football Club this evening confirmed they had reached agreement for the sale of Xabi Alonso to Real Madrid, subject only to a medical," the statement said. "The terms of the deal will remain confidential and undisclosed." Real confirmed the agreement in a statement on their website. Spanish media reported the deal was worth around 30 million euros, which would take Real Madrid's close-season spending up to around 250 million euros. Alonso came up through the youth ranks with Real Sociedad and was one of Rafael Benitez's first signings when he took charge of Liverpool in 2004, moving for 10.5 million pounds. He quickly became a Kop favourite helping them win the European Cup in 2005 and the FA Cup the following year. Alonso has also been a regular feature in the Spain squad since 2003 and was a part of Luis Aragones's victorious side at Euro 2008. Benitez fought hard to keep a player central to his plans but media reported it was Alonso who requested a transfer. The nine-times European champions have been keen to land an experienced defensive midfielder, who is also a good passer of the ball, to give balance to a side packed with offensive talent. In response to a trophyless season made worse by arch-rivals Barcelona scooping a treble, new president Florentino Perez has set in motion a huge squad rebuilding programme at the Bernabeu. Alonso is set to become their eighth signing after defenders Alvaro Arbeloa and Raul Albiol, midfielders Cristiano Ronaldo, Kaka and Esteban Granero, and strikers Karim Benzema and Alvaro Negredo. As part of the rebuilding programme, defender Michel Salgado, 33, has agreed to leave Real after 10 years with the Primera Liga club.