Updated

James Shields was not surprised by the New York Yankees' drive to end their longest skid in four years.

Alex Rodriguez homered twice, Jorge Posada had two hits and the Yankees stopped a six-game losing streak with a 6-2 victory over the Tampa Bay Rays on Tuesday night.

Rodriguez tied it 1 with a fourth-inning homer and then put the Yankees ahead with a solo shot in the sixth off Shields (4-2).

"It was one of those games where they were fighting for a win after six straight losses and they came out playing," Shields said.

With Yankees managing general partner Hal Steinbrenner in attendance, New York ended its longest slide since dropping seven in a row from April 20-27, 2007.

"We needed a win," Yankees manager Joe Girardi said. "It is a big win for us. I don't want to say must-win, but as close as you can get to a must-win in the month of May."

David Robertson replaced Yankees starter Ivan Nova (4-3) with the bases loaded and one out in the sixth and New York ahead 2-1. The right-hander struck out B.J. Upton and Casey Kotchman.

"Robertson was the game-changer," Tampa Bay manager Joe Maddon said. "He came in and quieted things down when we had a chance to get on top."

Posada doubled and singled while batting seventh as the designated hitter. It was his first start since he pulled himself out of the lineup Saturday soon after he was set to bat ninth.

Rodriguez has 621 career home runs. He recorded his first multihomer game this season and 59th overall.

It was just his second multihit game since April 23 — he had hit .171 (14 for 82) with one homer and six RBIs since then.

"My struggles have been really unacceptable, but hopefully today was the start of good things to come," Rodriguez said.

Elliot Johnson homered for the AL East-leading Rays (24-18), who are 11-13 at home this season. Ben Zobrist had a run-scoring double in the ninth with two outs that resulted in the Yankees using closer Mariano Rivera to get the final out in a non-save situation.

"We had opportunities," Maddon said. "We just couldn't get the hit tonight."

Tampa Bay has been held to three runs or less in 21 of 42 games.

Posada doubled and went to third on Brett Gardner's bunt single in the seventh. Posada was replaced by pinch-runner Eduardo Nunez, who scored on Chris Dickerson's single during a two-run inning that made it 4-1. Dickerson was called up from Triple-A earlier in the day when setup man, and former Rays closer Rafael Soriano was put on the disabled list.

The Yankees failed to score in the third with a runner on second and one out when Derek Jeter and Curtis Granderson struck out. In the bottom half, Johnson homered on a 3-2 pitch from Nova as the Rays went ahead 1-0.

Gardner and Jeter both had RBI singles in the ninth.

Nova gave up one run and four hits in 5 1-3 innings. Shields, who entered 4-0 over his previous five starts, allowed four runs and eight hits over seven innings.

Shields is 1-5 in eight career home starts against the Yankees.

Johnny Damon had three of Tampa Bay's six hits. The DH has three hits in a game three times this season.

Notes: New York special adviser and Hall of Famer Reggie Jackson will celebrate his 65th birthday Wednesday. ... Maddon said both Reid Brignac and Johnson will get playing time at shortstop. ... Tampa Bay LHP J.P. Howell (left shoulder surgery) threw 1 1-3 innings for Class A Charlotte and is expected to rejoin the Rays on Friday. ... Rays RHP Andy Sonnanstine, whose rotation spot was in question, will start Friday at Florida.