Wade Miley pitched two-hit ball into the seventh inning and Eric Chavez drove in three runs to help the Diamondbacks end a three-game losing streak.
The Rays finished with a 21-5 record in July, the best one-month record in franchise history. They started the month in third place, 5 games out in the AL East, and eventually took over the division lead.
"I can't sit here and bemoan anything right now," manager Joe Maddon said. "They're not robots. They're going to have a bad night on occasion, and the other team had a really good night. So it was a bad combination for us, but we'll wrap this month up and remember it."
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.
"It was a disappointing outing, to say the least," said Hellickson, who lost for the first time since June 13 and snapped a six-game win streak over seven starts. "I couldn't really command anything and I didn't make a pitch when I needed to. It's just one of those games that I've got to put behind me and move on."
Not that pitching was the Rays' only problem. They left nine men on base with 0 for 6 hitting with runners in scoring position.
Miley (8-8) won for the fourth time in five starts. He struck out eight in 6 1-3 innings and walked five.
"We had a couple opportunities we needed to take advantage of against him to get that momentum coming back to us, and it didn't happen," Maddon said. "I really can't get too upset. It's been a pretty good July, one of the funnest Julys I've ever participated in."
"I have no problem with the month, man. They outplayed us tonight," he said.
A close call at first base kept alive a two-run first inning for the Diamondbacks. After Hill barely beat out an infield single to load the bases, Cody Ross drove in the first two runs with a single.
"The way the game began took a little bit out of us and we never really recovered," Maddon said.
Said Hellickson: "Obviously, it would have been nice if he'd called him out, but it's still a 0-0 ballgame after that and I've got to make a pitch to the next batter to get out of that."
Paul Goldschmidt hit his 24th homer, scored three runs and reached base four times. Ross had three straight hits and drove in two runs for Arizona, which outhit the Rays 14-3.
Ben Zobrist got two hits for the Tampa Bay, and rookie Wil Myers extended his hitting streak to 12 games.
Chavez homered for the second straight day, a two-run shot that gave the Diamondbacks a 4-0 lead in the second.
"It's just refreshing for us," said Chavez, who drove in Arizona's only two runs Tuesday night with a ninth-inning homer. "We were struggling offensively, so it was really good to get off to a good start like that."
Arizona added single runs in the seventh, eighth and ninth against three different relievers.
NOTES: The crowd of 25,095 included approximately 9,700 fans who purchased $2 tickets through a discounted kids program. It was the Rays' largest midweek crowd since opening day. ... 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.