They had slugged away for more than three hours, trading outright winners and gaffes, when Novak Djokovic, the world’s No. 1 player, and challenger Stanislas Wawrinka each became an immovable force.

It was the third game of the fifth set on the Arthur Ashe Stadium court with a place in Monday’s U.S. Open final at stake. The contenders were deadlocked in a game that seemed to have no end until finally, in the 21st minute and on the 30th point, Wawrinka won it after weathering 12 deuces and fending off five break points.

Logic dictated that the victor of that soul-sapping game would go on to win the match.

But Djokovic, 26, who had started poorly and played from behind all afternoon, tapped some deeper reservoir of will to earn the 2-6, 7-6 (8-6), 3-6, 6-3, 6-4 triumph and reach a fourth consecutive U.S. Open final.

“I just tried to hang on and fight and be mentally tough and believe all the way through I can actually win,” said Djokovic, the 2011 U.S. Open champion, after the 4 hour, 9 minute semifinal that brought the capacity crowd to its feet for sustained cheers and wild applause.

Djokovic will face No. 2 seed Rafael Nadal, his greatest rival, who easily dispatched eighth-seeded Richard Gasquet, 6-4, 7-6 (7-1), 6-2, in the semifinal that followed.

Monday’s final will mark the third time in four years that Djokovic and Nadal have met for the U.S. Open title. They split their previous clashes, with Nadal winning in 2010 and Djokovic prevailing in 2011.

Tendinitis sidelined Nadal for last year’s tournament. But he has shown no ill effects after returning to competition in February.

Saturday against Gasquet, a longtime friend and former childhood rival, Nadal dropped his serve for the first time in the tournament. But while Gasquet unloaded a full arsenal of shots, including the game’s most artful one-handed backhand, Nadal was never threatened and closed the match in 2 hours, 21 minutes.

“It’s always the biggest challenge you can have in our sport right now,” Djokovic said of the prospect of facing Nadal, who has a 59-3 record this year and is unbeaten (21-0) on hard courts. “He’s the ultimate competitor out there. He’s fighting for every ball, and he’s playing probably the best tennis that he ever played on hard courts.”

It will be the 37th meeting between the two. Nadal holds a 21-15 edge in the rivalry, but Djokovic claims an 11-6 advantage on hard courts.

Wawrinka came out the aggressor in his match against Djokovic, his first semifinal appearance in a major, blasting forehand winners and serves clocked at 138 miles per hour.

Djokovic, regarded as the game’s most nimble mover, looked sluggish by contrast and was broken three times in the opening set, which he lost in just 34 minutes. It was only the second set that Djokovic had dropped all tournament.

The Serb’s ragged play continued in the second set, in which he fell behind 2-4, tallying twice as many errors as winners to that point and turning frequently to his box, where his coach, Marian Vajda, looked on. Soon after, Djokovic was slapped with a code violation for receiving coaching — an infraction that’s rarely called given the murky line between gestures that convey encouragement and those that suggest tactics.

The chatter with his box muzzled, the Serb went on to break back, force a tiebreak and level the match at one set apiece.

But the momentum shifts continued, with Wawrinka claiming the third set and Djokovic the fourth.

Then came the marathon game, which was a mini-match in itself, taking longer to settle than some of Serena Williams’ s sets during her march to Sunday’s women’s final.

The most riveting single point followed the ninth deuce — a brilliant 35-stroke rally that tested the limits of both players and ended on an overhead that Djokovic had set up with a masterful lob. Djokovic raised his right fist in triumph, while Wawrinka, who had sprinted nearly to the stands in pursuit of the Serb’s winning overhead, sat on the knee-high wall of the photographers’ pit to catch his breath.

It was only one point, and it settled nothing. But it sent the message that neither player was willing to relent.

Wawrinka finished with 57 winners to Djokovic’s 38, yet committed 69 errors to the Serb’s 46. They won precisely the same number of points: 165.

“I was playing better than him, but he’s not number-one for nothing,” Wawrinka said. “He was staying with me all of the match. At the end, he pushed me far, far, far back. I had to find everything I had in my body to stay with him. And he won the match.”