Davydenko had beaten Federer in their previous two meetings and began confidently to roll through the opening set before grabbing an early break in the second.
The Russian had all the momentum but Federer responded to the challenge in emphatic style as he peeled off the next 13 consecutive games and leave his Russian opponent stunned.
Davydenko, who had won his previous 13 matches, regained his composure to briefly threaten in the fourth set, but again Federer withstood the challenge to book his place in a record 23rd consecutive grand slam semi-final.
"I've played him many times and I know he goes through phases although they weren't a notch on what he did in that first set." Federer said.
"I just tried to stay positive. I wasn't playing bad but he was just playing so well.
"It was obviously a bit of a surprise to come back that great because obviously he has been on an incredible run."
The Swiss also revealed he had used a toilet break to his advantage at the end of the first set after Davydenko had broken him twice to take the initiative.
"I was having problems with the sun in my eyes also in the opening set," Federer said.
"I was waiting for it to move. I never use my toilet breaks so I thought I will use it and I hoped that maybe in that time the sun would move maybe one centimetre, maybe three.
"It might have been one point that it affected, but maybe that is important in the end."
His relief break did not work immediately as Davydenko again broke and went 3-1 ahead before the Swiss reeled off the next 13 games in a row.
The run handed Federer the second and third sets as well as a break in the fourth.
Davydenko had gone an hour without winning a game when he held to love and then broke to level at 3-3.
But after the players traded breaks again, and Federer failed to serve out the match, the Swiss finally landed the final blow with a cross-court winner.