Rafael Nadal won his 19th grand slam title with a thrilling five-set victory over Russia's Daniil Medvedev at the US Open.

The Spanish second seed led by two sets and a break before 23-year-old Medvedev, playing in his first major final, launched an astonishing comeback.

However, Nadal ran out a 7-5 6-3 5-7 4-6 6-4 winner to move to within one title of Roger Federer's record total of 20.

Hot-headed Medvedev had revelled in his new role as public enemy number one of the New York crowd.

The 23-year-old had been jeered by those in the stands throughout the fortnight after he flipped them the middle finger during the third round.

Yet when he launched an unlikely counter-attack in the third set it was like Rocky in reverse, the fans around a packed Arthur Ashe suddenly chanting his name.

However, Nadal dug as deep as he has probably ever had to to secure a dramatic victory in four hours and 50 minutes.

Nadal, whose hackles were raised when he was given a time violation at break point down in the very first game, took the opening set with a break at 6-5 thanks to a whipped forehand winner and a lob which Medvedev dumped into the net.

The Russian saved four break points in his next two service games but the jabs kept on landing, Nadal breaking through again for 4-2 and taking a two-set lead.

Fatigue seemed to be setting in for Medvedev, who was being pushed all around the court, and when a backhand hit the net at break point in the fifth game of the third set he looked beaten.

But he kept swinging, somehow breaking back to level, and with the crowd now firmly behind their new darling, he repeated the dose at 6-5 to take it to a fourth set with Nadal now the man looking vulnerable.

Gutsy hold after gutsy hold followed until Nadal sent a forehand wide and Medvedev had a break point, which he dispatched with a stunning return to force a decider.

It was sensational stuff, but the odds were still stacked against Medvedev. He had never before won a five-set match and Nadal had lost only twice from two sets up in his career.

Nadal's delaying tactics were irking the Russian but he fashioned two break points, then a third, only for Nadal to escape again.

When Nadal eked out a break point of his own at 2-2, Medvedev aced him. But when Nadal created another, a double-handed backhand putting him back in control.

Still the drama continued.

Nadal broke again but, serving for the match, he was given a second time violation by umpire Ali Nili and docked a serve at break point down, and promptly sent his second serve wide. Umpiring controversy is not confined to Serena Williams here, it seems.

Medvedev saved two match points on serve but when Nadal had the ball in his hand again he finally got over the line, a long Medvedev return bringing to an end a truly remarkable final.