NEW YORK – Through a pair of back-and-forth sets, Novak Djokovic and Andy Murray put on a display befitting a matchup of past U.S. Open champions.

They tracked down would-be winners and somehow got them back, prolonging points that involved 10 or 20 strokes or more, extended by Djokovic’s slides and splits or Murray’s gifted anticipation. After one 30-shot masterpiece on his way to victory, Djokovic raised his right fist, bellowed, “Come on!” and windmilled his arms to rile up the crowd.

“I knew coming into tonight’s match that it’s going to be tough, that he’s going to go for his shots, and the more aggressive one would win it,” the No. 1-ranked and No. 1-seeded Djokovic said. “I’m glad I managed to stay fit in the end and pull it through.”

It took a while for him to push out front in a 3-hour, 32-minute match that ended after 1 a.m. Thursday.

Asked in an on-court interview to look ahead to facing 10th-seeded Kei Nishikori of Japan in Saturday’s semifinals, Djokovic joked: “My thoughts are just directed to sleeping right now.”

That drew guffaws from spectators, and he continued: “Or party. What do you say? Let’s party. I think my coach right there would chase me with a little baseball bat if he saw me going to the city to party right now.”

Nishikori became the first man from Japan to reach the U.S. Open semifinals since Ichiya Kumagae in 1918, outlasting third-seeded Stan Wawrinka of Switzerland 3-6, 7-5, 7-6 (7), 6-7 (5), 6-4.

In the women’s quarterfinals, top-seeded Serena Williams dropped the first three games before quickly turning things around to defeat 11th-seeded Flavia Pennetta of Italy 6-3, 6-2.

Williams, who counts five U.S. Open titles among her 17 Grand Slam trophies, will play 17th-seeded Ekaterina Makarova of Russia in the semifinals.

Taking advantage as the eighth-seeded Murray’s lively forehand dipped in quality and the Scot’s service speeds slipped, Djokovic broke to go up 3-1 in the third set, then fended off a pair of break points in the next game. On the first, Murray sailed a backhand long to end a 28-stroke point, then leaned over and put a hand on his knee. On the second, he dumped a forehand into the net, then slammed his racket against his right thigh and yelled.

Soon, Murray was turning to his box to say, “Nothing in the legs.” In the fourth set, a trainer came out to deliver a heat pack to Murray.

“I got stiff in my hips and my back. … I don’t know exactly why,” said Murray, who beat Djokovic in the finals at the U.S. Open in 2012 and Wimbledon in 2013. “I didn’t hurt anything. It was just, I think, fatigue.”

He had back surgery a year ago, and dealt with cramping in his first-round match in New York last week. Murray looked fine since then, but he couldn’t sustain his top form against the relentless Djokovic, who won the U.S. Open in 2011.

“He was fresher toward the end,” Murray said. “I tried to hang in as best I could.”

Until the third set, anyway, Djokovic-Murray was reminiscent — in terms of pure entertainment value and setting, if not quite star power — of the 2001 classic between Pete Sampras and Andre Agassi, which also was a quarterfinal, and also under the lights at Arthur Ashe Stadium. That one, won by Sampras, featured four tiebreakers, because neither man broke serve even once.

Djokovic and Murray combined for 11 service breaks, seven by Djokovic, including in the final game. They are both brilliant baseliners and retrievers, and it helps that they know each other — and each other’s patterns — so well.

Wednesday’s opening set was a 73-minute exercise in shape-shifting and shot making. In the tiebreaker, though, Murray lost his way: He double-faulted, put a return into the net, flubbed a backhand and, before he knew it, that set was gone.

Djokovic went up a break in the second set. Murray broke back. Djokovic took another of Murray’s service games. And, yes, Murray again broke back, delivering a forehand winner that left an angered Djokovic swatting a spare ball off the serve-speed digital readout.

“We always,” Djokovic said afterward, “push each other to the limits.”