Not since 2003 had Federer lost before the semi-final stage at Flushing Meadows, winning five titles in that time, and he went into the tournament on a high after a stellar summer.
But Berdych had not read the script and he produced a performance of devastating power to stun the world number one 7-6 (7/1) 6-4 3-6 6-3 and set up a semi-final clash with Andy Murray on Saturday.
Federer clearly had not seen this coming and mostly he was disappointed with himself for making too many errors, especially in the first two sets.
He said: “I really expected myself to play better tonight [Wednesday]. Especially at night, I have had such a great record.
“I felt good. It’s such an amazing summer I had. I really thought I was going to come out and play a solid match. I didn’t do that tonight. Obviously there is a bit of a letdown now.”
Federer had never lost in 23 night-session matches at the US Open while Berdych had never played one until Wednesday night, but the conditions were certainly to his liking.
It seemed like it would be business as usual when Federer began brilliantly and broke serve in the first game, but Berdych was also playing at a high level and, when the top seed’s dropped, the Czech capitalised.
The first-set tie-break was a bit of a horror show from Federer and he was in huge trouble at two breaks down in the second set.
He retrieved one but Berdych did not waver serving out the set and then went a break up in the third, to the disbelief of the huge crowd, who were firmly behind Federer.
Finally the 31-year-old stirred, reeling off five games in a row to get one set back, but in a fourth set of supreme quality it was Berdych who struck first in the eighth game and four huge serves finished off the job.
Federer did not feel the walkover he had in the previous round courtesy of Mardy Fish’s withdrawal had been a factor and had hoped winning the third set would prove the turning point.
He said: “I still was down two sets to one, so I wasn’t celebrating too much.
“It was good. The momentum switch no doubt gave me a chance, put the score back to zero, put him further away from winning, and made the match go longer, make it more physical, more mental.
“Obviously I was excited winning the third, but the problem was the first couple of sets, particularly the first one.”
It was Berdych’s second consecutive win over Federer at a grand slam after he also beat him at the same stage of Wimbledon in 2010 before going on to reach the final.
Addressing the crowd afterwards, Berdych said: “It couldn’t be better. There is no better feeling than to play my first night session against Roger and be able to beat him. There is no better moment than this.”
It was even more of a shock because the world number seven has had a poor summer, losing in the first round of both Wimbledon and the Olympics.
He said: “Probably everything was just right today. I lost the third set. But I cannot think I’m going to be beating Roger in straight sets and not to get in any trouble.
“So I was always careful that anything could happen. He came back strongly. But I’m even more happy with the way that I was able to hold his pressure and then add something extra for the fourth set.”
Federer is guaranteed still to be number one at the end of the tournament because Novak Djokovic is the defending champion and cannot gain points, but the Swiss player’s brilliant indoor season last year means he faces a battle to finish 2012 on top.
He said: “I’ve got to go back to the drawing board from here and see what’s really the priority, if that’s a priority for the end of the year.
“We’ll see where I go from now and if I go to Davis Cup or not, what’s to come for the remainder for the season.
“Number one has another a role to play, but this obviously is a setback. But the season is not over. I hope to finish strong at the end and particularly in the indoor season.”