Racing announced on Monday that Madrid had paid the full amount required to release the midfielder from his contract, with the deal reported to be worth three million euros.
Martinez made an impressive start to the new season and scored against Villarreal in Racing's opening La Liga match. However, the young midfielder is expected to begin his Real Madrid career with the club's reserve side.
He becomes the latest arrival in a busy transfer window at the Santiago Bernabeu, with Real Madrid also bringing in several other players, including record signing Yan Diomande.
The club have strengthened their squad after going two consecutive seasons without winning a major trophy, and Jose Mourinho's new-look side have made a perfect start to the La Liga campaign.
Real Madrid have won all three of their opening league matches as Mourinho looks to lead the Spanish giants back to the top.
Real Madrid's next men's match is against Real Betis in La Liga on Friday away at the Estadio de La Cartuja in Seville.