Roger Federer looks on during a quarterfinal match against Tomas Berdych, of Czech Republic. Federer, the top seed on the men’s side, was eliminated in four sets. (Darron Cummings/ASSOCIATED PRESS)

Roger Federer’s resurgent summer ended at the hands of the hard-hitting Tomas Berdych of the Czech Republic shortly before midnight Wednesday night at the U.S. Open.

Berdych blasted 14 aces and seized on 40 unforced errors by the Swiss to oust the five-time U.S. Open champion in the quarterfinals, 7-6 (7-1), 6-4, 3-6, 6-3.

It was Federer’s first defeat in a night match on Arthur Ashe Stadium, snapping a streak of 21 consecutive victories under the lights at the world’s biggest tennis venue. And though the crowd fell silent when the sixth-seeded Berdych won the first two sets, it wasn’t the first time Federer had lost to the Czech in the quarterfinals of a major. Berdych ushered him out of Wimbledon at the same stage in 2010.

“I’m disappointed,” said Federer, 31. “I really expected myself to play better tonight, especially at night. I’ve had such a great record, and such an amazing summer I had. I really thought I was going to come out and play a solid match, and I didn’t do that.”

Federer entered the U.S. Open as the top seed, favored to extend his record of major titles to 18. He had hardly put a foot wrong in months, winning a seventh Wimbledon and reclaiming the No. 1 ranking. And his path to Wednesday’s quarterfinals was almost gilded. He didn’t lose a set in his first three matches, and he advanced in the fourth round when American Mardy Fish withdrew hours before their match.

But it seemed Federer paid a price Wednesday for such an easy road, having not competed in four days. His backhand was off-target. His normally reliable serve betrayed him. And he had trouble countering the big serve of the 6-5 Berdych.

After losing the first two sets, Federer found much of what he had lacked in the third set, winning points with artful backhand slices, lunging stab volleys and well-placed serves. He broke the Czech twice. Serving for the set at 5-3, he blasted two huge serves and followed with deft drop shots.

The fourth set was tight until the eighth game, in which two poor forehands cost Federer his serve. And Berdych served out the match with ease. It was the first time since 2003 that Federer failed to reach the U.S. Open semifinals.

“There is no better moment than this one, so far,” said Berdych, 26, who next faces No. 3 seed Andy Murray in the semifinals. Murray overcame a shaky start to defeat Marin Cilic 3-6, 7-6 (7-4), 6-2, 6-0 earlier in the day.

In other action, Maria Sharapova reached the semifinals for the first time since 2006, defeating Marion Bartoli 3-6, 6-3, 6-4. She’ll face top-seeded Victoria Azarenka.

Three-time champion Serena Williams stormed into the semifinals, keeping her string of straight-sets victories intact by dismissing former No. 1 Ana Ivanovic 6-1, 6-3 in 58 minutes. The 30-year-old Williams blasted 12 aces and finished with 26 winners to her opponent’s six.

She’ll next face Italy’s Sara Errani, who defeated compatriot and doubles partner Roberta Vinci 6-2, 6-4.

Defending U.S. Open champion Novak Djokovic eased into the quarterfinals when Stanislas Wawrinka retired, trailing 4-6, 1-6, 1-3. Djokovic will face Juan Martin del Potro, who ousted Andy Roddick 6-7 (7-1), 7-6 (7-4), 6-2, 6-4 in the final match of the American’s career. And Serbia’s Janko Tipsarevic defeated Philipp Kohlschreiber 6-3, 7-6 (7-55), 6-2.