Danilo Gallinari scored 29 points to lead the Nuggets to a 116-113 victory over the slumping Heat on Sunday night.
Gallinari shot 11 of 19 from the field as the Nuggets (36-40) snapped a three-game losing streak and got within two games of the idle Portland Trail Blazers for eighth place in the Western Conference playoff race.
"I was trying to be aggressive," Gallinari said. "My teammates did a great job finding me open. I'm just glad we got the W."
Miami, which overcame an 11-30 start and got to within one game of .500 on three separate occasions the past two weeks, has lost four of its last five at home. Before its winless two-game homestand, the Heat (37-40) were seventh in the Eastern Conference, but they now trail seventh-place Chicago (38-39) by a game and are tied for eighth with Indiana (37-40).
Jamal Murray's two free throws with 9.5 seconds left, after a second consecutive inbounds play, gave Denver its winning margin. Josh Richardson's game-tying 3-point attempt at the buzzer failed to hit the rim.
"They guarded the play well," Richardson said. "I just took the look I had. The clock was about to run out."
The Heat contested that Nikola Jokic should have been called for a traveling infraction on the first inbounds attempt. Jokic called time and inbounded the ball on the second try.
"I wasn't nervous, I just knew we were going to get it," Jokic said.
Jokic's jumper with 55.1 seconds left put the Nuggets ahead 114-110 before Tyler Johnson's 3-pointer with 10.8 seconds remaining cut the margin to 114-113.
Jokic finished with 19 points and 10 rebounds and reserves Wilson Chandler and Emmanuel Mudiay scored 19 and 17 points, respectively, for the Nuggets, who will continue their five-game road trip Tuesday at New Orleans.
"We've been in a lot of close games this year," Denver coach Michael Malone said. "We struggled to win some of them but tonight, obviously, was great to pull it out and get that win in a game that was really important for both teams."
After trailing the first three quarters, the Heat took their first lead, 94-93, on Richardson's 3-pointer 1:52 into the fourth period.
Goran Dragic scored 22 points and Richardson finished with 17 points for Miami. After consecutive road victories over Detroit and New York, the Heat lost two straight at home to the Knicks and Nuggets. Miami will begin a three-game road trip Wednesday at Charlotte.
"I mean this is like our playoffs right now," Miami coach Erik Spoelstra said. "Our guys are laying it all out there but we just haven't been able to get the job done the last couple of games. Now we'll have to quiet all the noise."
The Nuggets played their second straight without injured point guard Jameer Nelson and reserve guard Will Barton. Nelson missed Sunday's game because of a left calf strain and Barton was sidelined because of left knee soreness.
Mudiay received his most extensive playing time since March 1. Mudiay, who didn't play because of a coach's decision in 10 of the Nuggets previous 14 games, played 32 minutes against Miami and finished with nine assists in addition to his 17 points.
NOTES: For the fifth time this season, the Nuggets recalled G Malik Beasley from the Sioux Falls Skyforce of the NBA Developmental League. Beasley, a rookie from Florida State, averaged 18 points per game with the Skyforce and had four earlier stints with the Nuggets in which he averaged 2.4 points in 19 games. ... Former Villanova coach Rollie Massimino, who led the Wildcats to the 1985 national championship, was a special guest of Denver coach Michael Malone Sunday and accompanied the Nuggets during shootaround and pre-game meal at the team's hotel. Massimino, 82, coaches at Keiser University in West Palm Beach, Fla. and his grandson, Tommy Jr., is an assistant video coordinator on the Nuggets' staff. ... Miami G Dion Waiters has begun conditioning but is yet not cleared to practice. Waiters missed his eighth consecutive game Sunday because of a sprained left ankle he sustained March 17. ... The Heat is 0-8 on Sundays and finished 14-16 against the Western Conference.