Carmelo Anthony scored 42 points and Chauncey Billups had 30 for Denver, which overcame a nine-point deficit in the last 2:51 to win.
Afflalo scored seven points to help the Nuggets rally from 119-110 down. Nene hit 1 of 2 free throws with 33.3 seconds left to tie it, and Dirk Nowitzki hit one free throw with 19.6 seconds left to give Dallas a one-point lead.
Denver chose not to call a timeout, and Billups found Afflalo, who got a shot off before the horn to lift Denver. Afflalo finished with 24 points.
Jason Terry scored 25 points, Tyson Chandler had 20 points and 11 rebounds and Nowitzki finished with 16 for the Mavericks.
Anthony fouled out when he was guarding Nowitzki on Dallas' last possession.
Anthony told the Denver Post on Wednesday before Denver's game against Golden State that he would "take a real hard look" at signing the three-year, $65 million extension the Nuggets offered last summer if he is not dealt before the Feb. 24 trade deadline.
Anthony has been mentioned in trade talks with New Jersey, Chicago, New York and the Los Angeles Lakers since the start of the season.
The Nets were his hottest pursuers until owner Mikhail Prokhorov announced last month his club was no longer trying to deal for Anthony.
Anthony has said in the past he has wanted to keep his options open and wasn't opposed to playing the entire year in Denver.
Until Wednesday he had not indicated he was open to signing the extension and staying in Denver beyond this season.
Dallas, which trailed by 18 in the first half, took control in the third and tried to pull away in the fourth. Denver led 75-71 when the Mavericks went on a 13-2 run to take the lead.
Dallas led 92-88 heading into the final 12 minutes when Terry hit a 3-pointer and a jumper as the Mavericks scored the first nine points of the fourth to take a 13-point lead.
After sitting out Wednesday with a left knee strain, Billups was aggressive offensively in the first quarter, hitting four 3-pointers and scoring 18 of the team's first 31 points and the Nuggets took a 33-19 lead.
Denver quickly pushed the lead to 18 early in the second before Dallas rallied behind its bench, which scored 31 of the team's 39 points in the period.
The Mavericks trailed by 18 before Chandler's free throw with 1:09 left in the half tied the game at 54. Jose Berea hit a 3-pointer to put the Mavericks up 58-56 before Anthony hit a 3 to give Denver a one-point lead at the break.
Notes: Miami Dolphins receiver and former Denver Broncos player Brandon Marshall was sitting courtside. ... With Jerry Sloan resigning as Utah's coach, Denver's George Karl is now the third-longest tenured coach in the NBA. Karl took over the Nuggets in January 2005.