Houston, playing without Dwight Howard (knee injury), ended its two-game skid and snapped the Mavericks' six-game winning streak.
Dallas led by four with less than a minute remaining before Harden made two free throws. Monta Ellis missed on the other end and Harden put Houston on top 93-92 when he made a jump shot and the ensuing free throw with 28 seconds left.
Harden stole the ball from Ellis and Trevor Ariza made two more free throws to seal the victory.
Dallas had a chance to tie it but Dirk Nowitzki and Ellis each missed 3-pointers in the final seconds.
Ellis led the Mavericks with 17 points and Brandan Wright had 14 points and 11 rebounds.
Houston led by as many as 18 points and was up by eight when the Mavericks scored 13 straight, with seven from J.J. Barea, to take an 86-81 lead with about 3½ minutes left.
Houston had turnovers, an offensive foul and even missed a layup as Dallas went on top. The Rockets scored their first point in more than 6 minutes when Donatas Motiejunas made a free throw with 3:14 remaining.
With Howard out with a strained right knee for the second game, the Rockets, who lead the league in 3-pointers a game this season, relied on long-range shooting heavily in the first half and had 13 by halftime. They cooled off in the second half and finished with 15.
Dallas scored four quick points to cut the lead to 11 with about 7 minutes left in the third quarter. But Houston scored seven straight points after that to make it 73-55. The Mavericks missed four consecutive shots and had a turnover as the Rockets padded the lead.
Dallas finally got going after that -- outscoring Houston 13-4 the rest of the quarter to get within 77-68 entering the fourth quarter.
The game was tied at the beginning of the second quarter before Houston used a 22-10 spurt to take a 51-39 lead about 6 minutes before halftime. That run was powered by six 3-pointers, including four in a row to end it.
Harden and Chandler got into a little dustup a couple of minutes after that. It started when Chandler seemed to inadvertently hit Harden in the face, knocking him to the ground on the continuation of a play where Harden was called for traveling.
Chandler tried to help him up but Harden shook off the help. Harden then pushed Chandler from behind on the right arm as he walked away, drawing a technical foul. The play was reviewed and Chandler was given a technical, too.
The Rockets trailed early before using a 13-2 run which started with three straight 3-pointers to take a 16-9 lead. Harden made the first one in that span and Patrick Beverley sunk the other two.
Harden's 3 gave Houston a 60-51 lead at halftime.
Mavericks: Dallas made just six 3s a night after making 18 in a win over the Lakers to tie a franchise record. ... Chandler had 13 points and led the team with 13 rebounds.
Rockets: F Terrence Jones missed his ninth straight game with nerve inflammation in his left leg. ... Beverley left the game in the fourth quarter with a sore hamstring and didn't return.
Mavericks: Host Indiana on Monday.
Rockets: Host the New York Knicks on Monday
Carmelo Anthony said he's already talking with free agent Kevin Durant about possibly joining him with the Knicks.
With a little help from nine-time Grammy winner Justin Timberlake, director Craig Brewer shows Mike Conley why he should stay in Memphis.
Former Cavaliers and Lakers coach Mike Brown will replace Luke Walton as Steve Kerr's top assistant with the Warriors, sources told ESPN's Marc Stein.