Brandon Moss and Jorge Bonifacio added solo shots.
The Royals trailed 2-0 entering the sixth inning before Lorenzo Cain led off with a walk to finish the night for starter Mike Pelfrey.
Left-hander David Holmberg (1-3) relieved Pelfrey, who walked six but had allowed just two hits.
After retiring Eric Hosmer, Holmberg gave up a two-run homer to Perez to tie it. Moustakas promptly homered, marking the seventh time this season the Royals have gone back-to-back. Moss homered two batters later.
Moustakas homered again in the eighth for his sixth multi-homer game of his career.
Bonifacio led off the seventh with his 12th home run.
Scott Alexander (2-3) picked up the victory after replacing Jason Vargas in the sixth.
The White Sox lost their eight in a row. The Royals have won four in a row and are tied for second in the American League Central, 1 1/2 games behind the Cleveland Indians.
Vargas, who had given up 12 runs in 7 2/3 innings in losing his first two July starts, held the White Sox to two runs in the first five innings.
Melky Cabrera homered on an 0-1 Vargas offering in the third. He poked it 360 feet into the left-field seats for his 13th home run of the season.
Cabrera's two-out double to the right-center gap in the fifth scored Tyler Saladino, who had walked. Cabrera had three of the five hits off Vargas in the first five innings.
Lorenzo Cain led off the fourth with a single for the first Kansas City hit and Hosmer drew his second walk. Perez, however, nearly grounded into a triple play. He hit a slow roller to third baseman Yolmer Sanchez, who stepped on the bag and threw to second forcing out Hosmer. Perez just did beat Yoan Moncada's relay throw to first.
Alex Gordon singled with two outs in the fifth and Whit Merrifield walked. Pelfrey got out of that by retiring Bonifacio on a grounder to second.
NOTES: The Royals recalled RHP Jake Junis from Triple-A Omaha for his fifth stint with the big league club. Junis was 2-4 with a 2.55 ERA in 10 starts for Omaha They optioned OF Billy Burns to the Storm Chasers. ... White Sox SS Tyler Saladino made his sixth start at shortstop as Tim Anderson was given the night off. ... The heat index was 112 degrees for the first pitch. Royals LHP Danny Duffy tweeted: "Jesus turn down the furnace, or take the wheel, or something along those lines idk. I feel like I'm medium rare. ... LHPs Derek Holland of the White Sox and Travis Wood of the Royals are the Sunday probables.