Gurriel's blast came in the first inning and Thomas went deep in the sixth. Gabriel Moreno went 4-for-4 for the Diamondbacks (77-72), who are tied with the Cincinnati Reds for the National League's third wild-card berth.
Arizona is just 1 1/2 games behind the second-place Cubs (78-70) in the wild-card race after beating them for the fourth time in five meetings over the past nine days.
Brandon Pfaadt (2-8) gave up four hits in 5 1/3 scoreless innings to win his second big league contest in 17 appearances (16 starts). He struck out six and walked one while helping Arizona halt a three-game slide.
Chicago Cy Young Award candidate Justin Steele (16-4) served up both homers on first-pitch sliders while losing for the first time since July 16. Steele gave up a season-worst six earned runs and allowed seven hits, two walks and struck out five in six innings.
Ian Happ, Seiya Suzuki and Christopher Morel all homered in the ninth for the Cubs, who have lost three straight games and six of their past eight. Chicago is 5 1/2 games behind the first-place Milwaukee Brewers in the NL Central.
In the ninth, Kyle Nelson served up Happ's solo shot to left and Suzuki's two-run blast to left. It was the 18th homer of the season for both players.
Paul Sewald entered with one out and Morel hammered his first pitch over the wall in left to pull Chicago within two on his 23rd homer of the season. Sewald then retired the next two hitters to end it.
Arizona grabbed the lead in the bottom of the first as Ketel Marte led off with a single and Christian Walker drew a two-out walk. Gurriel followed with his 24th homer of the season, a 413-foot blast to left for a 3-0 lead.
In the sixth, Walker walked and Moreno laced a two-out single. After a mound visit, Thomas hammered the first pitch from Steele over the fence in right-center field for his ninth homer of the season.
—Field Level Media