By Joshua Schneyer

NEW YORK (Reuters) - If being well rested was all Novak Djokovic needed to win the U.S. Open for his third grand slam title of the year, the world number one would have sailed through Sunday's final against Swiss Stan Wawrinka.

The 29-year-old Serb came into the U.S. Open final with less than nine hours playing time at the tournament, completing just three of his six matches. He was gifted with a walkover in the second round and two other opponents retired due to injuries.

Wawrinka, on the other hand, played nearly 18 hours of tennis to reach the final. 

Instead, it was 12-times grand slam winner Djokovic who flinched first from exhaustion and pain in a hard-fought, four-hour battle, which Wawrinka won 6-7(1) 6-4 7-5 6-3.

By the final set, Djokovic said, bleeding toes were severely crimping his mobility. 

    After sailing through a tiebreaker 7-1 to win the first set, Djokovic looked like he might be able to notch a relatively quick victory, crowning a season in which he became the third man ever to hold all four slam titles at once.

But Wawrinka, known for his endurance and blazing one-handed backhand, turned up the pace to capture the second set.

By the end of the third, an epic 76-minute battle that left Djokovic grimacing in the later games, Wawrinka was looking like the steadier player.

In the second game of the fourth set, Djokovic began grimacing in pain during his service game and hobbling between points. It appeared to be cramping or a leg injury, and the Serb repeatedly hit his thigh with his racket.

Djokovic called a controversial medical break down 1-3 in the fourth set, and a trainer went to work taping up his toes.

ESPN TV commentator John McEnroe, for one, speculated that Djokovic was getting leg cramps, the kind of injury that is not eligible for treatment by a trainer on court. 

Djokovic insisted cramping was not the problem. "Just the toenails were off and bleeding. It was quite painful to move around," he told reporters.   

    Though Djokovic emerged from the medical break with more spring in his step, he was not able to break Wawrinka again, a persistent problem that may have cost him the match as he converted only three of his 17 break point opportunities.

Djokovic said later he had considered not coming to the U.S. Open at all, due to what he described as an injury that was "very serious at the time," without elaborating.

He has had a nagging wrist injury and a lackluster Wimbledon, exiting in the third round. Later he lost in the first round at the Rio Olympics. Earlier at the U.S. Open, there was also speculation about a possible shoulder injury. 

  "I really didn't know whether or not I'm going to come, to be honest," Djokovic said, saying he made the decision to play in New York just days before the tournament. 

Djokovic, however, said there was no reason to expect injuries to hamper his play during the rest of the season or next year. 

(Reporting By Joshua Schneyer; Editing by Larry Fine)