Shawn Marion had 12 points and a season-high 15 rebounds for the Mavericks, who beat Houston for the fifth straight time.
Goran Dragic scored 24 points, and Luis Scola added 19 for the Rockets, who had all five starters in double figures.
The Mavericks came into the game with only a half-game lead over Houston, Utah and Denver in the tightly bunched Western Conference standings. The game had a playoff feel, with 17 lead changes, 15 ties and a louder-than-usual crowd with the in-state rival in town.
Nowitzki split two free throws with 10.9 seconds to go to put the Mavericks up 91-88, and get the hundreds of Dallas fans in attendance standing and cheering.
But Chandler Parsons then swished a 3-pointer over Jason Kidd to tie it with 3.3 seconds remaining. Kidd tried a lob to Wright on a set inbound play, but Courtney Lee swatted it away and Terry's last-second shot from the free-throw line bounced off the rim.
The Mavericks took a 97-93 lead in overtime. Scola sank two free throws to cut the deficit to two and Lee hit a long jumper that initially appeared to be a 3-pointer. But the officials reviewed the shot and ruled that Lee's foot was over the line, and the game was tied at 97-all with 90 seconds left.
Dragic then was whistled for an offensive foul for pushing off Nowitzki. The Dallas star was cut over his right eye and went to the bench for a bandage. Terry then hit a pull-up jumper with 36 seconds to go, and Wright blocked Lee's jumper on Houston's next trip.
Nowitzki sank two free throws with 18 seconds remaining to make it 101-97. With the points, Nowitzki moved past Charles Barkley and into 19th place on the NBA career scoring list (23,758).
Dragic drove for a reverse layup, and the Mavericks were called for a backcourt violation, giving the Rockets one more chance to tie it.
Chase Budinger missed a 3-pointer from the corner at the buzzer, and the Mavericks beat Houston for the 12th time in the last 16 meetings.
The Mavericks won for only the second time in their last 10 road games, despite getting outrebounded 52-38. Houston went 9 for 25 from 3-point range (26 percent), but only 37 of 96 (38.5 percent) overall.
The Rockets led for much of the first half, but Kidd hit back-to-back 3s — one from six feet beyond the arc — during a 12-4 Mavericks' run in the second quarter. The Mavericks surged ahead with Nowitzki on the bench, and he returned for the final two minutes of the half.
Parsons just beat the buzzer with a layup then cut Houston's deficit to 56-54 at the break. Nowitzki scored 16 points in the first half, then made four shots in the first six minutes of the third quarter.
Nowitzki then missed a baseline shot and a straight-on 3-pointer, and Odom substituted for him with Dallas leading 68-66. Lamar Odom made a bad pass in traffic, and Parsons streaked the other way for a tying layup with 3:33 left in the third quarter.
Neither team led by more than four through the tense fourth quarter. The Rockets led 86-83 when Wright broke open for a layup and Terry swished a straight-on 3-pointer to put the Mavericks on top 88-86.
Notes: The Mavericks are 15-1 when scoring 100 points this season. ... The Mavs' bench outscored Houston's reserves 44-13. ... Scola blocked three shots, tying his career high. ... Yao Ming and his wife, Ye Li, sat courtside with 22-month-old daughter Yao Qinlei. The girl will turn 2 on May 21. ... The in-state rivals were meeting for the first time this season. They'll play again Tuesday night and on April 18, both times in Dallas.