The Rockets took a two-point lead with 3:41 to play, but the Mavericks then came up with back-to-back baskets from Mayo -- one of them a 3-pointer -- and a jumper by Dirk Nowitzki to move in front for good.
Dallas did not clinch the win, however, until Darren Collision hit two free throws with 4.7 seconds to play.
Nowitzki and Shawn Marion both scored 22 points to lead the Mavericks while Mayo had 13 points and a career-best 12 assists. Dallas had lost four of its last five games, but this victory moved the Mavericks within 4 1/2 games of a playoff spot.
James Harden scored 28 points for Houston and was perfect in his 16 free throw attempts.
The teams had met in Houston last Sunday with the Rockets winning that one by 33 points.
Puzzle-maker slips 'Murdoch Is Evil' into Rupert Murdoch's Sunday Telegraph
Wisconsin business offering 'therapeutic cuddling' forced to close