DeMarcus Cousins added 14 points and 11 rebounds.
The Kings connected on a season-high 12 3-pointers in the victory, helping to end a three-game losing streak. They return home Monday to host New Orleans.
The Magic fell to 0-13 when opponents have scored 100 or more points. They have lost four of their last five, and four straight at home.
The Magic clung to a two-point lead entering the final quarter, but were outscored 18-4 in the first five minutes as the Kings took a 93-81 lead.
Sacramento maintained its cushion until a 3-pointer and layup by Harris got the Magic within 98-93 with 3:25 to play.
After getting a stop on the other end, Afflalo got free on a fast break but his layup attempt rolled off the rim.
Cousins then got a layup on the other end and was fouled. He missed his free throw, but was fouled again. He then made 1 of 2 free throws to make it 101-93.
The Magic kept scrapping, and got down to 101-97 with under a minute to play.
They had the ball with 55.4 seconds, but turned it over on the inbounds play when Afflalo slipped near the sideline and Victor Oladipo's pass sailed over his head and out of bounds.
Thomas then banked in a running 12-footer to extend the Kings' lead to six.
Kings coach Michael Malone tore into his team's defensive effort following Friday's loss at Miami.
He went as far as questioning their commitment on that end of the floor after giving up 70 points in the paint to the Heat.
But he also acknowledged before Saturday's game that it would take more practice time before recent trade acquisitions Gay, Quincy Acy and Aaron Gray to get comfortable in the Kings' systems.
The trio have been active for six games since the trade, but gotten in only one full practice with their new teammates in that span.
Gay, who has started all six of his games with Sacramento, was sluggish early against the Magic and missed his first five shots before finally getting on the board late in the second quarter.
His teammates backed him up, though, shooting above 50 percent for the second straight game.
With Afflalo back in the lineup, the Magic had a much better flow from the outset offensively.
They shot a season-low 32 percent in their loss to Utah, but recovered to shoot 47 percent against the Kings.
The Magic never trailed in the opening 24 minutes, taking their biggest lead at 54-42 before being outscored 14-4 to end the half.
NOTES: The Kings won their first road game since Dec. 7. ... Oladipo had a streak of 16 consecutive starts end Saturday night. ... Cousins received a technical foul with 5:08 left in the fourth quarter for arguing with referee Ken Mauer.