Madrid: “Real Madrid and Porto have reached an agreement for the transfer of Danilo, who will join next season and be tied to the club until June 30, 2021,” the club said in a statement.
A statement by Porto to the Portuguese stock exchange said the deal was worth 31.5m euros (£23m).
The 23-year-old joined Porto from Santos in 2012 and has won two league titles with the Portuguese giants, as well as playing a big part in their run to the quarter-final of this season’s Champions League, where they will face Bayern Munich next month.
Danilo also won a silver medal with Brazil at the 2012 Olympics.
He has become a regular with his national team since Dunga took charge of the five-time world champions following a disappointing World Cup on home soil last year.