"I definitely got very lucky out there, " a relieved Federer told BBC Sport after winning in three hours and 18 minutes to book a second-round meeting with Serbia's Ilija Bozoljac.
Radek Stepanek and Tomas Berdych defeated Nenad Zimonjic and Ilija Bozoljac 6-4 6-2 7-6 (7-4) in a match which lasted two hours and 23 minutes on the clay at the O2 Arena.
"I'm unhappy with the way I'm playing, I couldn't play the way I wanted to, " added the Swiss, who needed five sets to overcome Alejandro Fall in the first round and four to oust Ilija Bozoljac in the second.