Real Madrid have signed Real Sociedad midfielder Asier Illarramendi after agreeing to meet the Spain Under-21 international's buy-out clause.

Sociedad announced Friday that Madrid had informed the Liga de Futbol Profesional (Spanish Football League) they would pay the clause, reported to be 39million euros ($50.85m), to bring the 23-year-old to the Bernabeu.

The two clubs had been in negotiations regarding a fee for a player Madrid believe to be the long-term replacement for Xabi Alonso in a defensive midfield role, but had failed to find a resolution.

A Madrid statement read: "Real Madrid have signed Asier Illarramendi, who is now tied to the club for the next six seasons.

"The player will be presented tomorrow after undergoing the relevant medical tests."

Illarramendi rose to prominence as a key man at Sociedad last season, playing an important part as the San Sebastian club finished fourth in the Primera Division , securing a place in the Champions League in the process.

He then played every game as Spain Under-21s won the European Under-21 Championship in Israel earlier this summer.

He becomes Madrid's fourth signing of the summer, after fellow Spaniards Isco and Dani Carvajal joined from Malaga and Bayer Leverkusen respectively, and the club made their loan move for Brazilian midfielder Casemiro permanent.