He fell to no. 26 in the world until his season changed after winning the 2007 Madrid Masters. He won the tournament by defeating second seed Rafael Nadal, third seed Novak Djoković, and top seed Federer in consecutive rounds, becoming the third player after Boris Becker and Djoković to defeat the world's top three players in a single tournament. He defeated Nadal, 6–1, 6–2, in the quarterfinals. His good form carried him to his second top-3 win of the tournament, defeating Djoković in the semifinals. He stunned Federer in the final, 1–6, 6–3, 6–3, and reached the doubles semifinals with Guillermo Cañas in the tournament, before losing to top-seeded brothers Bob and Mike Bryan in the semifinals. After the tournament, his singles ranking moved up from no. 25 on the tour to No. 18.