Federer's title at the grass-court tournament in Stuttgart, Germany, last week pushed him up from No. 2 on Monday.
Nadal dropped down from No. 1 after sitting out last week following his 11th French Open championship earlier in the month.
This is the fifth time the top ranking has changed hands between Federer and Nadal. That's the most switches at No. 1 in a single season since there were also five in 2003.
The record for most changes at No. 1 is 10, set in 1983, when John McEnroe, Jimmy Connors and Ivan Lendl all spent time there.
This is Federer's record-extending 310th week at No. 1.