The right-back left los Blancos last summer in search of regular first-team football but the club inserted a buy-back clause in his contract which enabled them to re-sign the Spain Under-21s international for a €6.5 million (£8.3m) fee within the first three years of his contract with the Bundesliga club.
|REAL MADRID LATEST
|11/2||Real Madrid are 11/2 with Bet365 to win the Champions League
"Today I'm the happiest person in the world. I will give my all for this club."
Madrid president Florentino Perez also welcomed the defender's arrival and backed the 21-year-old to make his mark at the Santiago Bernabeu.
"Today, many 'Madridistas' are happy for you - you have returned home. Dani, welcome to Real Madrid," he said.
"You know the demands of this club. Now your opportunity has come, and I know you'll make the most of it. You, Dani, know the values of this club to perfection."
Carvajal has signed a deal until 2019 and made 34 appearances in all competitions for Leverkusen last season.