ST. PETERSBURG, Fla. -- Max Scherzer tried to focus on simply giving his team a chance to win.

The Detroit right-hander struck out seven in six innings and Miguel Cabrera had four hits and drove in two runs, helping the Detroit Tigers to a 5-2 victory over the Tampa Bay Rays on Thursday night.

Scherzer (7-5) allowed two runs and four hits in his second start after the death of his brother earlier this month. The right-hander was replaced after walking the only batter he faced in the seventh inning.

"As difficult as the time is for me, you know for me it's about going out there and pitching well and helping the team," Scherzer said. "We want to win. Any time I can go out there and give our team a chance to win, that's what I'm all about."

Cabrera hit a solo homer in the ninth inning and had two singles and a double to continue a hot stretch in which he's hit .342 over the past 46 games. The slugger has 11 RBIs in his last 13 games and seven homers in June after hitting nine in 51 games over April and May. His run-scoring single off James Shields (7-5) gave Scherzer a 4-1 lead.

Delmon Young, Alex Avila and Quintin Berry also drove in runs for the Tigers off Shields, who allowed four runs and a career-high 14 hits in 7 2/3 innings. Austin Jackson had four hits off the Rays starter, helping Detroit end a two-game losing streak while extending Tampa Bay's skid to four.

"We were able to swing the bat good. When you swing good (good things happen)," said Cabrera, who's batting .312 with 16 homers and 62 RBIs.

Scherzer, who has won six of his past eight decisions, gave up a RBI single to Elliot Johnson in the fifth inning. He walked Jeff Keppinger leading off the seventh, and Tampa Bay scored its second run when Brooks Conrad doubled off reliever Phil Coke and Berry mishandled the hit into the left-field corner for an error.

Tigers manager Jim Leyland said Scherzer has been more consistent with his delivery lately.

"When he gets the right arm slot going, and is not flopping around off the mound ... he's pretty consistent," Leyland said.

"It was a good game. ... We pitched very well," Leyland added. "We got some big hits. Scherzer was good. The bullpen was good."

The Rays have lost seven of nine and are 5-11 since June 11, when they were last in first place in the AL East. They're 1/3 against the Tigers this season and have dropped 10 of 12 to them.

Scherzer left the Tigers this month after his brother's death. He returned two days later and allowed three runs and three hits over six innings of a 4-1 loss to Pittsburgh on June 23.

Young, Avila and Berry staked Scherzer to an early three-run lead in this one that could have been much larger.

The Tigers had a runner thrown out at the plate in the fourth and stranded eight while scattering 11 hits off Shields through the first five innings. They scored twice in the third, but may have had a much bigger inning if perfectly positioned Rays second baseman Keppinger hadn't snared Cabrera's rising liner and turned what likely would have been a run-scoring extra-base hit into an unassisted double play.

Scherzer didn't allow a runner past first base until Conrad doubled off the right-field wall and scored on Johnson's one-out single in the fifth for Tampa Bay.

Coke and Joaquin Benoit got the Tigers through the seventh and eighth innings. Jose Valverde pitched the ninth to earn his 14th save in 17 opportunities.

Detroit finished with 15 hits, including 11 singles off Shields.

"They found every single hole you can possibly find. There's nothing you can do about it," the Rays starter said.

Shields didn't take solace in keeping his team close and pitching deep into the game.

"You can compete all you want, and you can go deep into the game all you want," Shields said. "But the bottom line is you lost the game. I've got to do a better job."

Game notes

Rays 3B Evan Longoria, out since May 1, hasn't resumed baseball activities since feeling discomfort in his injured left hamstring during a minor league rehab assignment that was cut short on June 18. ... Tampa Bay activated DH Luke Scott (back stiffness) from the 15-day disabled list and optioned RHP Chris Archer to Triple-A Durham. RHPs Jeremy Hellickson (right shoulder inflammation) and Kyle Farnsworth (right elbow strain) are expected to return from the DL on Saturday. ... Tigers DH Victor Martinez had a follow-up MRI that shows improvement in his injured left knee. The best case scenario for a return this season remains mid-to-late September.