Mariano left Madrid for Lyon a year ago for €8 million but the Ligue 1 side have agreed a deal worth a possible €30m (£27m/$35m) for the striker.
Mariano has signed a five-year deal with Madrid and he will be presented to the club's fans at the Santiago Bernabeu on Friday.
Earlier on Wednesday, Lyon president Jean-Michel Aulas indicated Mariano's move to Madrid was imminent.
"Mariano told us that he absolutely wanted to leave, the offer from Sevilla arrived without being solicited," Aulas told reporters. "Keeping a player against his will is a bad preparation for a healthy season.
"With Sevilla, we found an agreement but then Real Madrid came and had an option to buy. We did not think they were going to use it, but they did it yesterday morning."
Mariano made a great start to life in France, scoring 18 league goals in 2017-18, but he has not found the net since April.
His arrival will ease the goalscoring burden on Karim Benzema and Gareth Bale following the shock sale of Ronaldo to Serie A champions Juventus in a €112m deal after the Portugal captain helped Madrid to win their third consecutive Champions League title in May.
"We cannot announce the replacement of Mariano yet. His arrival and the departure of Mariano will be connected," Aulas said.
"Moussa Dembele is a target, yes. But I also read that Marseille were on it. Is it harder for them than for us? Yes, I think so.
"We came into contact with Moussa Dembele. The player is interested in Lyon but Celtic are hard in negotiations. There are other targets."