The Brazilian will join the club in the summer following months of speculation linking him with a move to Carlo Ancelotti's side

Real Madrid have confirmed the €31.5 million signing of Porto right-back Danilo, who has signed a contract until 2021.

The Brazilian, 23, has been linked with a move to the European champions for months and Danilo confessed a week ago he was proud of reported interest from Carlo Ancelotti's side.

And on Wednesday night, the two clubs announced the defender would be leaving the Dragao this summer to sign a six-year contract at the Santiago Bernabeu.

"Porto hereby informs the market that it has reached an agreement with Real Madrid for the permanent transfer of Danilo for the value of €31.5m," the Portuguese club said in a statement to the stock market.

Madrid also confirmed in a statement that the Brazil international would be joining the club after reportedly seeing off competition from rivals Barcelona for his signature.

Danilo has been ever-present in Julen Lopetegui's side in his fourth season at the club, bagging four goals and four assists as Porto have progressed to the Champions League quarter-finals.

His arrival at the Santiago Bernabeu will raise fresh doubts over the future of current first choice right-back Dani Carvajal.