Federer, seeded second behind Novak Djokovic and chasing his first title since Cincinnati last August, could get a quarter-final clash with his great rival Rafael Nadal, who was to play Latvian qualifier Ernests Gulbis in the fourth round later Wednesday.
The Basel native improved to 13-1 against Wawrinka, but he had to labour two hours and 20 minutes to do so.
Serving for the match at 5-4 in the second set he was broken at love.
Unable to convert two break points in the following game he surrendered the set on a tiebreaker when he double faulted on set point.
Wawrinka then gained the upper hand with a break in the third set, but Federer, owner of 17 Grand Slam titles broke back in the next game and earned the decisive break in the final game as Wawrinka smacked a volley into the net.
"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."