ST. PETERSBURG, Fla. - Andrew McCutchen drove in two runs, Jeff Locke pitched into the eighth inning, and the Pittsburgh Pirates beat the Tampa Bay Rays 6-5 on Tuesday night.

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 in the eighth when Evan Longoria trimmed the Rays' deficit to 6-3 with a two-run homer.

Mark Melancon got his 13th save despite giving up Brandon Guyer's two-run single in the ninth that pulled Tampa Bay to 6-5.

Chris Archer (4-5) gave up five runs and seven hits in seven innings for the Rays, who have lost 20 of 28.

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 first 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 Logan Forsythe hit a two-out triple, a routine-looking fly ball that Polanco appeared to lose 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. Josh Harrison had a sixth-inning RBI single and Russell Martin hit a solo homer in the eighth.

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

NOTES: 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. ... Tampa Bay manager Joe 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.