The Kings had a six-point lead heading into the final period, but wilted down the stretch and saw their losing streak reach six games.
Ellis made a layup while being fouled with 12.4 seconds to play and the ensuring free throw gave the Mavericks a five-point lead.
Marcus Thornton then kept Sacramento's hopes alive by hitting a 3-pointer, but Ellis converted two free throws with 4.6 seconds left to put the game away.
Nowitzki scored 34 points, hitting 11-of-19 from the field and making all 11 of his free throws. Ellis chipped in 20 points and Jose Calderon had 14 points and seven assists.
Rudy Gay poured in 35 points for the Kings, going 15-of-17 from the line.