Updated

Elliot Johnson and Ben Zobrist homered, Carlos Pena ended an extended slump with two doubles and two RBIs, and the Tampa Bay Rays held on to beat the Baltimore Orioles 9-8 Sunday and avert a three-game sweep.

James Shields earned his sixth win for the Rays, who snapped a three-game skid and won for only the second time in eight games. Tampa Bay entered the series tied atop the AL East with Baltimore.

This victory was anything but easy. The Rays led 7-1 in the fourth inning and 9-6 in the eighth, but it was 9-8 when Fernando Rodney got Matt Wieters to ground out in the ninth with runners on second and third with two outs.

Rodney got his 10th save in 10 tries in a game that earlier appeared was going to be blowout.

Zobrist had three RBIs and Johnson scored three runs and drove in two. Pena was 3 for 37 with 14 strikeouts in May before hitting a third-inning double and adding a two-run double in the fourth to make it 7-1.

After Baltimore closed to 7-6 in the seventh, Johnson and Zobrist hit successive homers off Troy Patton in the eighth for a 9-6 lead. The nine runs were the most scored by the Rays since April 19, and they needed every one of them.

Wieters and Nick Johnson homered and Nick Markakis had three RBIs for the Orioles, who were denied their first three-game home sweep of Tampa Bay since 2007.

Shields (6-1) gave up six runs, four earned, and seven hits in 6 1-3 innings. The right-hander is 9-5 lifetime against Baltimore, including 6-1 at Camden Yards.

Shields retired eight straight batters before J.J. Hardy doubled in the sixth. Markakis followed with an RBI double and Wieters hit his eighth homer to make it 7-4.

A throwing error by Tampa Bay second baseman Will Rhymes preceded Markakis' two-run double in the seventh.

After Elliot Johnson and Zobrist connected in the top of the eighth, Nick Johnson hit a solo shot in the bottom half, his second homer in three games off Joel Peralta.

Orioles starter Jake Arrieta (2-4) allowed seven runs and a career-high 10 hits in 3 2-3 innings. The right-hander has yielded 13 earned runs in his last 10 innings and has only one win in seven starts since opening day.

After stranding runners at the corners in the first inning, the Rays went up 3-0 in the second when Elliot Johnson hit an RBI single and Zobrist followed with a two-run double.

Wieters led off the bottom half with a double and scored on a single by Chris Davis.

In the Tampa Bay third, Rhymes snapped a 0-for-13 drought by bringing home Pena with a two-out single. The Rays went up 7-1 when Matt Joyce singled in a run and Pena delivered a two-out double.

NOTES: Tampa Bay's B.J. Upton struck out four times. ... Orioles OF Xavier Avery, the team's second-round pick in the 2005 draft, went 0 for 4 in his major league debut. ... Rays C Chris Gimenez and his wife, Kellie, celebrated their first Mother's Day together with their 5-month-old son Jace. Kellie started her road trip in New York for the series against the Yankees. ... The Orioles open a two-game series against the Yankees on Monday. RHP Jason Hammel (1-3, 6.69 ERA lifetime against NY) will start for Baltimore. ... Tampa Bay will send Jeff Niemann to the mound Monday night in Toronto. ... Baltimore has lost six straight on Mother's Day.