Gattis followed an infield single by George Springer and walks to Jose Altuve (intentional) and Brian McCann. Royals left-hander Matt Strahm (0-2) ran the count full to Gattis before his final pitch sailed high to force home Springer.
Center fielder Jake Marisnick, a defensive replacement in the eighth, homered off Royals closer Kelvin Herrera with one out in the ninth to send the game into extra innings.
The Royals (2-4) coughed up a two-run lead in the seventh when Astros first baseman Marwin Gonzalez golfed his third homer of the season into the Crawford Boxes in left field, doing so against Royals left-hander Travis Wood and driving home Gattis in the process.
Brandon Moss hit his first home run off Astros right-hander Chris Devenski (1-0) to give the Royals a 4-3 lead in the top of the ninth and followed dingers by Salvador Perez in the second and Mike Moustakas in the sixth.
Perez and Moustakas homered off Astros right-hander Lance McCullers, who allowed three runs and six hits with 10 strikeouts in seven innings.
Devenski had seven strikeouts in four innings of relief for Houston (4-3).
Making his first road start since June 20, 2016, with the Seattle Mariners, Royals right-hander Nate Karns produced a strong effort. He surrendered a leadoff home run to Astros center fielder George Springer in the bottom of the first and was unscathed after that.
Houston mustered five additional hits off Karns, all singles, running into three outs on the bases in the first and second innings.
When Karns departed with two outs in the sixth, he led 2-1. He posted three strikeouts against two walks and benefited from two double plays.
NOTES: Astros 2B Jose Altuve recorded his 200th career stolen base with two outs in the eighth inning. Altuve became the seventh Houston player to reach that milestone. ... Royals C Salvador Perez homered in his fourth consecutive game, becoming the first Kansas City player to accomplish the feat since Billy Butler on July 26-29, 2011. ... Astros RHP Lance McCullers has allowed three or fewer runs in each if his 22 career starts at Minute Maid Park. The only pitcher in club history with such a streak is RHP Larry Dierker, who also did so in 22 consecutive starts in 1970-72.