Paul Goldschmidt hit his 24th homer, scored three runs and reached base four times. Cody Ross had three straight hits and drove in two runs as Arizona broke a three-game losing streak.
Arizona outhit the Rays 14-3. Ben Zobrist got two hits for the Tampa Bay, which despite the loss finished its best month ever at 21-5.
Miley (8-8) won for the fourth time in five starts. He struck out eight in 6 1/3 innings and walked five.
Miley has made 11 straight starts of giving up three earned runs or fewer.
Jeremy Hellickson (10-4) gave up four runs and seven hits in 4 1/3 innings, the shortest Rays start since Alex Colome also went 4 1-3 innings on June 22.
Chavez homered for the second straight day, a two-run shot that gave the Diamondbacks a 4-0 lead in the second.
Hits by Martin Prado, Aaron Hill and Ross had produced two runs in the first.
Arizona added single runs in the seventh, eighth and ninth against three different relievers.
NOTES: LHP Joe Thatcher, acquired by Arizona earlier in the day in a trade that sent pitcher Ian Kennedy to San Diego, will join the Diamondbacks in Texas on Thursday. … Arizona RHP Zeke Spruill will get his first major league start Thursday against the Rangers. … With LHP Matt Moore moving to the 15-day disabled list, the Rays will start Chris Archer, David Price and Roberto Hernandez in their weekend series at home against the San Francisco Giants.Suggest a correction