Updated

The Tampa Bay Rays' latest defeat had a little different twist — four late runs and six hits that left them one run short of the Pittsburgh Pirates.

Andrew McCutchen drove in two runs, Jeff Locke pitched into the eighth inning and the Pirates beat the Rays 6-5 on Tuesday night, handing Tampa Bay its 20th loss in 28 games.

"The moral victories are not what we're looking for right now; we're looking for the actual victories," Rays manager Joe Maddon said. "I love the idea that the winning run came to the plate. ... There's a lot of good things to draw from tonight, but we can't continue to lose this type of game."

Russell Martin's fourth home run gave the Pirates a 6-1 lead, but Evan Longoria hit a two-run home run off Locke in the eighth. Singles by Logan Forsythe, Desmond Jennings and Brandon Guyer produced two more runs off closer Mark Melancon in the ninth, but Longorida flied out to end it.

"We were maybe a hit away or something, but it happens," said Guyer, who scored on Longoria's 10th home run in the eighth. "We just have to bring the momentum into the game tomorrow and try to get a win."

The Pirates have the NL's best record (27-18) since May 6, and moved above .500 (39-38) for the first time since starting the season 7-6.

McCutchen had an RBI single during a three-run third inning that put the Pirates ahead 4-0. The 2013 NL MVP had two RBIs in Pittsburgh's 8-1 win Monday night over the Rays.

Locke (1-1) allowed three runs and eight hits over 7 1-3 innings. His night ended with Longoria's homer. Melancon got his 13th save.

Chris Archer (4-5) gave up five runs and seven hits in seven innings for the Rays.

"We lost. We got an L, but we played hard and I don't know that there was much more we could do, other than me not walking two leadoff hitters," Archer said. "That ultimately was the difference in the game."

Pirates left fielder Starling Marte left in the fifth inning with concussion-like symptoms after a head-first slide during a failed stolen base attempt. He made contact with Rays second baseman Sean Rodriguez on the play.

Gregory Polanco started the game with a walk, stole second and advanced to third on catcher Jose Molina's throwing error, and scored to make it 1-0 on a grounder by McCutchen. Polanco has reached base in all of his 14 games since being recalled from Triple-A Indianapolis on June 10.

Tampa Bay got within 4-1 in the fifth when Forsythe hit a two-out triple and Jose Molina followed with an RBI double. Molina, who has two RBIs in 43 games this season, is 2 for 34 with runners in scoring position.

Marte hit a run-scoring single and Neil Walker had a sacrifice fly in the third, a three-run inning which started with a walk to Pedro Alvarez.

Walker returned after being on the 15-day disabled list since June 9 because of an appendectomy.

NOTES: Kevin Kiermaier pinch hit for Rays SS Yunel Escobar in the eighth, partly because of a sore right shoulder than will keep Escobar out of the lineup for Wednesday's series finale. ... Pittsburgh manager Clint Hurdle should announce Wednesday when RHP Gerrit Cole (right shoulder fatigue) will return to the rotation. Cole threw a simulated game Monday, which lines him up to start this weekend. ... Tampa Bay C Ryan Hanigan was scratched due to neck stiffness. ... Maddon said RHP Jeremy Hellickson (right elbow surgery) will need at least one more minor league start before returning. ... NASCAR driver Aric Almirola took batting practice and gave Maddon a Rays' racing helmet. ... Tampa Bay LHP David Price (5-7) and Pirates RHP Charlie Morton (4-8) are Wednesday's scheduled starters. Price, the subject of trade speculation, said he has thought about the situation and it's the reason why he's been in a "bad mood" recently.