The 33-year-old Spanish left-hander moved one shy of Roger Federer's all-time men's record 20 Grand Slam triumphs and became the second-oldest New York champion in the Open era after Ken Rosewall in 1970 at age 35.
World number two Nadal took the top prize of $3.85 million at Arthur Ashe Stadium and added to his US Open trophy haul from 2010, 2013 and 2017.
Nadal, who was in his fifth US Open championship match and 27th Grand Slam final, is the first man to claim five major titles after turning 30.
But it took a supreme effort from the Spanish maestro, who nearly became the first player to drop the final after leading by two sets since Frederick Schroeder in 1949.
Nadal, who rose to 22-12 in five-set matches, has dropped only one Grand Slam match out of more than 200 when he has won the first two sets, the loss coming at the hands of Italy's Fabio Fognini in the 2015 US Open third round.
At four hours and 50 minutes, the match finished four minutes shy of equaling the longest final in US Open history from Mats Wilander's 1988 win and Andy Murray's 2012 title.
It was the second Slam title of the year for Nadal after taking his 12th French Open crown in June.
In addition to reaching the brink of Federer's mark, Nadal moved one shy of the Open era record five US Open titles won by Federer, Jimmy Connors and Pete Sampras.
Nadal, who won his only prior meeting with Medvedev in last month's Montreal final, seldom looked threatened after being broken early in the match.
The Spaniard stretched his win streak over Russians to 20 matches since losing to Nikolay Davydenko in the 2011 Doha semi-finals.
Fifth seed Medvedev, 23, battled throughout his first Grand Slam final but could not become the youngest men's Grand Slam champion since Juan Martin del Potro at the 2009 US Open, falling to 0-5 in five-set matches.
Medvedev, who saw his career-best 12-match win streak snapped, would have been the first Russian to win a Grand Slam title since Marat Safin at the 2005 Australian Open and the first Russian to win the US Open since Safin in 2000.
At 6-foot-6 (1.98m), Medvedev also would have matched Marin Cilic and del Potro as the tallest champion in US Open history.
- Electric fifth set -
Nadal saved a break point in the second game of the fourth set when Medvedev netted a backhand and a huge Nadal chant roared from the stands.
Medvedev denied Nadal on two break chances in the fifth game as the tension built. Then Nadal was broken in the 10th game to drop the set, Medvedev blasting a backhand return winner to complete a five-point run to force a fifth set.
Nadal battled through the second game of the final set, denying three Medvedev break chances to hold.
Nadal fired a backhand volley winner to break Medvedev for a 3-2 lead, stretching to reach the Russian's drop volley and flicking a winner that brought a roar from the crowd.
Chants of "Ra-fa" echoed through the stadium as he held to 4-2 and Medvedev sent an overhead smash beyond the baseline to hand the Spaniard a break for a 5-2 edge.
Nadal served for the match but Medvedev took a break to 5-3 when umpire Ali Nili issued Nadal a time violation for his first serve and the Spaniard sent his second serve long, the crowd booing Nili for his violation call.
Nadal had two break and match points in the ninth game, but Medvedev fired a backhand winner and Nadal netted a forehand return as the Russian held to 5-4 and the drama intensified.
Again serving for the match, Nadal rescued a break point then hit a forehand drop volley for his third match point chance and took the victory when Medvedev sent a forehand return long.
Nadal screamed and fell to the court on his back after the epic showdown.
This year's US Open set an all-time attendance record with 737,872 fans watching over the Flushing Meadows fortnight.
More about: Rafael-Nadal