DENVER -- The Denver Nuggets' hot shooting from long range suddenly went cold, but with the game on the line, they found the first-half magic one last time.
Guard Randy Foye's 3-pointer with 1:11 left put Denver ahead for good and the Nuggets recovered after squandering a 17-point lead to beat the Dallas Mavericks 102-100 on Saturday night.
Forward Kenneth Faried had 18 points and 14 rebounds, including a key board on Dallas forward Dirk Nowitzki's miss with 14 seconds left, and guard Ty Lawson had 20 points for the Nuggets.
Nowitzki finished with a game-high 27 and guard Monta Ellis scored 25 for the Mavericks, who had their four-game winning streak snapped.
"Tough game. We did everything we could to get back in the game and take the lead," Ellis said. "They made free throws and we didn't make shots. Nothing we can do. Can't hold our heads."
The Mavericks were fighting to keep their win streak alive and to repay coach Rick Carlisle, whose emphatic reaction to a hard foul on Ellis in the second quarter earned him an early exit.
They almost did both, rallying from 57-40 down in the second quarter to take the lead late in the game.
"I thought we were garbage in the first half," Nowitzki said. "We really had to fight, claw our way back in it. I thought we had a great second half."
It helped that the Nuggets stopped hitting 3-pointers. They were 9-for-20 from long range in the first half but couldn't hit from there in the second. They missed their first seven shots from long range in the fourth quarter before Foye came through.
"I think we were just taking shots because we were up 16 or 17 points," Lawson said. "We thought we were going to just go ahead and win the game. We were taking shots out of character."
Denver led 96-91, but Dallas fought back and took a 100-98 lead on Nowitzki's jumper with 2:02 left.
Foye's 3-pointer gave Denver a 101-100 lead -- the Nuggets' only one of the fourth quarter -- and Ellis and Nowitzki both missed jumpers.
Faried got the rebound and hit a free throw.
"I work extremely hard on my shot so 5-for-12, 1-for-12, it doesn't matter, just got to continue to shoot the ball with confidence," Foye said.
Ellis missed a short jumper with 7.1 seconds left and Dallas got the ball back, but Nowitzki's jumper at the buzzer was off.
"I've got to be a little better down the stretch," Nowitzki said. "I think I missed my last two or three shots."
Denver led by 13 early in the third quarter, but Dallas chipped away, in large part because of forward Vince Carter.
Carter missed six of his seven shots from the field in the first half but found his rhythm after intermission. He hit all four of his 3-pointers and scored 14 of his 16 points to pull the Mavericks within 86-85 early in the fourth quarter.
Ellis' jumper from the top of the key gave the Mavericks an 89-88 lead, their first since the first quarter.
"We hung in and gave ourselves a chance," Carlisle said.
The Nuggets grabbed the lead with a 14-4 run to end the first quarter.
The Mavericks started fast in the second quarter to cut the lead to 37-32, but a dunk by Chandler and a 3-pointer from guard Nate Robinson sparked a 12-1 run that gave Denver a 16-point lead midway through the quarter.
Carlisle didn't stick around after that. He was upset when the refs didn't award Nowitzki two free throws on a foul by Chandler, and moments later became angry when Foye put a hard foul on Ellis.
After heatedly voicing his displeasure to official Tony Brothers, Carlisle was given two technicals and ejected.
"I thought the foul was excessive. I thought he fouled him and he came down on him extra hard," Carlisle said of the foul on Ellis. "I'm going to stand up for my players."
Foye said he was just trying to play good defense.
"C'mon, man, everybody knows me. I was about to help him up," he said. "I just pushed the ball down. I'm not going to do anything dirty."
Assistant Monte Mathis took over the head coaching duties for Dallas.
NOTES: The Nuggets entered Saturday shooting just 69.7 percent from the foul line, which ranked 29th in the league. ... Dallas F Dirk Nowitzki was the last player to record a triple-double against Denver. He had 34 points, 10 rebounds and 10 assists in Dallas on March 29, 2010. ... G Andre Miller's alley-oop pass to F Wilson Chandler's in the second quarter moved him into sole possession of ninth place on the NBA all-time assist list. He was tied with Rod Strickland and is nearly 1,000 assists shy of Gary Payton for eighth. ... Entering Saturday, the Mavericks split their first four back-to-back games this season. They were 3-1 in the second game of the back-to-backs.