The Mavericks ended a four-game losing streak and won for just the second time in 12 games.
Dallas appeared headed for another setback when they fell behind by nine points early in the fourth quarter, but the Mavericks went on a 22-8 run that gave them a five-point lead with 58 seconds to go.
Sacramento came back to tie it, however, when Isiah Thomas hit a 3-pointer with 9 seconds remaining.
The Mavericks led by three in the extra period when Marion hit his two foul shots with 22 seconds left. Tyreke Evans brought Sacramento back within three and Vince Carter then went to the foul line for Dallas.
Carter, however, missed both attempts to give the Kings a chance to tie it. Thomas then misfired from 3-point range and Mayo boosted the Dallas lead to five with 8 seconds left by making two from the line.
Mayo had 24 points and Marion scored 19 with both players pulling down 10 rebounds. Carter came off the bench to add 23 points and Dirk Nowitzki had 17.
DeMarcus Cousins scored 29 for the Kings and Evans chipped in 20.