Manu Ginobili scored 23 points for the top seeds, who were forced into a fight to level the series at 2-2.
San Antonio recovered from five points behind after the first quarter to take the lead in a second period which saw them score 32 points.
The Spurs continued their dominance following the break to build a 20-point lead at one stage, but the Mavericks fought back to set up a dramatic finish to the game.
Dallas eventually pulled within one of the Spurs, but the visitors held on to secure a four-point success as the Mavericks wasted crucial seconds in the closing stages.
The fifth match of the series will take place in San Antonio on Wednesday night.