Roger Federer was given a fright before overcoming compatriot Stanislas Wawrinka at the BNP Paribas Open in Indian Wells.
Federer, the second seed, was taken to the brink by his Davis Cup team-mate before he registered a 6-3 6-7 (7-4) 7-5 victory.
"I definitely got a bit lucky out here tonight," Federer said. "Stan's an amazing player and a good friend - I'm happy to get through."
Federer will now face old foe Rafael Nadal in the quarter-final after the Spaniard eventually toppled qualifier Ernests Gulbis 4-6 6-4 7-5.