It was the third straight win for the Rockets, who played without Dwight Howard (sprained ankle), and the fourth loss in a row for Dallas.
The Mavericks were down by 3 with 15.9 seconds left when Harden knocked Tyson Chandler down on a shot. He was given a flagrant foul after a review, but Chandler missed both free throws.
Terrence Jones blocked a shot by Monta Ellis but knocked it out of bounds, giving Dallas another chance. The inbounds pass by Chandler Parsons sailed out of bounds to give Houston the ball. Harden made two free throws after that to secure the win.
Ellis led the Mavericks with 33 points.
The Rockets had six players with 10 or more points.
Dallas scored five quick points to get within 3 with two minutes left, but Smith made a layup before blocking a shot by Chandler on the other end. Dirk Nowitzki made a layup before Harden's flagrant foul.
A 7-2 run by Houston pushed the lead to 95-87 with about three minutes left. That run was capped by a 3-pointer by Smith that came after an assist by Harden who was being heavily guarded by Rajon Rondo.
Corey Brewer made the first five points of the fourth quarter to extend Houston's lead to 86-78.
Nowitzki made four quick points to cut Houston's lead to 2 points late in the third quarter before Jason Terry's 3-pointer made it 81-76. A jump shot by Ellis got Dallas within 81-78 entering the fourth quarter.
Trevor Ariza was scoreless before opening the second half with a 3-pointer and he made another one with about nine minutes left in the quarter. That shot was the first points of a stretch during which he outscored Dallas 10-7 to leave Houston up 72-66. A third 3-pointer by Ariza, who had 13 points in the quarter, capped that run.
Parsons scored five points in an 8-2 run that tied it at 39 five minutes before halftime. Harden, who had eight assists, escaped pressure from Rondo with a nifty juke move and dished it Smith who made a 3 from the corner to leave Houston up 54-53 at halftime.
Dallas led 21-11 after a 7-0 run early. Houston finally found its offense after that, using three 3-pointers to outscore the Mavericks 13-4 the rest of the first quarter and cut it to 25-24 entering the second.
Houston forward Terrence Jones (left leg nerve inflammation) played for the first time since Nov. 3. His first points came with about 3 1/2 minutes left in the half when he stepped back and swished a 3-pointer to give Houston a 44-41 lead.
He finished with 10 points.
Mavericks: Parsons, who played his first three seasons in Houston before signing as a free agent with the Mavericks this offseason, got a smattering of boos every time he touched the ball in his second trip back. He had 21 points.
Rockets: Hall of Famer and former Rockets great Hakeem Olajuwon watched the game from a courtside seat. He was also at practice Tuesday working with Houston's big men. ... Wednesday was the second straight game Howard has missed and his 14th this season. ... Smith made a season-high four 3-pointers.
Mavericks: Visit Miami on Friday.
Rockets: Visit Boston on Friday.