The 17-time Grand Slam title winner, bidding to reach his 33rd Grand Slam semi-final and ninth in a row at the US Open, was beaten 7-6 (7/1), 6-4, 3-6, 6-3 by sixth-seeded Berdych.
"It couldn't be better," Berdych said. "There's no better moment so far than this one."
It was Federer's worst defeat at the tournament since losing to David Nalbandian in the fourth round in 2003.
Berdych, who went into the quarter-final with a 4-11 record against the world number one, will now face British third seed Andy Murray for a place in
Sunday's title match.
"I'll just try to bring something from today and try to add something a little more for my next match," Berdych said.
The 26-year-old Czech has reached the last four in New York for the first time while Saturday will be his first Grand Slam semi-final since he reached the Wimbledon final in 2010.
That was the tournament where he also defeated Federer in the quarter-finals.
In an extraordinary reversal of fortune, Wednesday's clash was Berdych's first appearance in a night match at the main stadium.
Wimbledon champion Federer, by contrast, went into the tie with a perfect 21 wins in his night-time outings.
There was no sign of the drama to come when Federer, who hadn't played since Saturday as a result of Mardy Fish's decision to withdraw from their fourth-round clash, broke to lead in the first game of the quarter-final.
But Berdych levelled at 3-3 before romping through the tie-break, taking the opener with his fifth ace.
The big Czech broke for a 1-0 lead in the second set with Federer under siege, having to save two break points in the fifth game.
His resistance cracked, however, under the relentless barrage as a brutal forehand, on the back of two double faults by the top seed, made it a
double-break for 5-2.
Federer retrieved one of the breaks in the eighth game before Berdych served it out with a love game in the 10th.
Berdych was 1-0 with a break in the third before Federer pulled it back at 3-3 when the Czech suddenly looked vulnerable with a third double fault of his own.
Federer held to love for 4-3, broke for 5-3 and then claimed the third set when Berdych failed to chase down a drop shot as the top seed looked to pull off a third fightback from two sets to love down in Grand Slams this year.
But Berdych settled himself to break for 5-3 in the fourth set and give himself a chance to serve for the match.
He went comfortably to three match points and claimed a famous win when Federer dumped a lame service return into the net, the last of his
uncharacteristic 40 unforced errors.