BALTIMORE - The Tampa Bay Rays took a break from their miserable season to put on a dazzling hitting performance against the Baltimore Orioles.

Now if they can find a way to sustain the momentum for a bit, the Rays just might make some real noise over the next three months.

Matt Joyce homered twice, had a career-high five hits and drove in four runs to power the Rays to a 12-7 victory Sunday.

Tampa Bay totalled 11 extra base hits — five homers and six doubles. The Rays trailed 4-3 before Kevin Kiermaier and Logan Forsythe went deep during a seven-run sixth inning that sent many in the crowd of 32,665 scattering toward the exits.

"We haven't had anything like that all year," Joyce said. "It was nice to come out here and win a big series and swing the bats like we did."

Ben Zobrist also homered for the Rays, who took three of four from Baltimore after starting the series with a 1-7 record against their AL East rivals. The 12 runs were Tampa Bay's second-most this season behind a 16-run outburst on April 19 against the Yankees.

The Rays still own the worst record in the majors, but now there's hope as Tampa Bay prepares for a three-game series at Yankee Stadium beginning Monday night.

"The season we've had, we're playing better baseball," Joyce said. "This was a big series for us going into New York. It was nice to come in here and swing the bats well."

Joyce doubled in the first inning, hit a solo shot in the third, singled in both the fifth and sixth innings and added a two-run drive in the seventh. His five hits and 12 total bases tied club records.

Although the Orioles finally got Joyce out in the ninth with the outcome already decided, his 5-for-6 performance upped his batting average 15 points to .274.

"You really don't have very many days like that," Joyce said. "It's nice to have one of those days and enjoy it."

Alex Cobb (3-6) got the win despite giving up four runs and eight hits in five innings.

"It's really important to keep it going," manager Joe Maddon said. "The focus has to be on winning series. We did this one."

Manny Machado and Ryan Flaherty homered for the Orioles. Flaherty hit a three-run drive in the ninth to snap an 0-for-16 skid.

But the 12 runs and 18 hits were the most allowed by Baltimore this season.

"Times like this, you'd like to come out with a W when you score seven runs," Orioles manager Buck Showalter said.

The game turned in the seventh, when the Rays set season highs with seven runs and seven hits. After Kiermaier homered off Evan Meek (0-3), Joyce singled in a run and James Loney delivered a two-run double. Brandon Guyer followed with an RBI double and Forsythe capped the barrage with a two-run homer off Brian Matusz.

"It's wonderful. We haven't really done that," Maddon said. "Balls are falling in, missing defenders, balls going over the wall. Good at-bats."

In the eighth, Joyce hit a shot to right to make it 12-4 and complete his third career two-homer game. Coming in, he had three home runs this season — none since May 11.

Tampa Bay went up 1-0 in the first inning when Desmond Jennings walked and scored on a double by Zobrist, who was thrown out trying to stretch it into a triple.

After Joyce homered in the third, Nick Markakis doubled in the bottom half and came home on a two-out single by Steve Pearce.

Machado put Baltimore up 3-2 with a two-run drive in the fourth. After Zobrist connected in the fifth to tie it, Tampa Bay loaded the bases before Meek replaced starter Miguel Gonzalez and struck out Forsythe.

Gonzalez gave up three runs and eight hits in 4 2-3 innings, his shortest outing in seven starts since May 5.

"Command," he said. "I've got to keep working on that. I think that has been my biggest issue this year. Other than that, I felt good."

Baltimore took the lead for the last time when Markakis scored on a passed ball to make it 4-3 in the sixth.

NOTES: Rays RH Chris Archer on Monday will attempt to become the first pitcher to win his first five games against the Yankees since Walter Johnson in 1907-08. ... Baltimore sends Ubaldo Jimenez to the mound in the opener of a four-game series against visiting Texas. ... The Rays played a fifth straight game without shortstop Yunel Escobar, who has a sore right shoulder. ... Markakis became the eighth player in Orioles history to have at least nine seasons with 100 hits.