Updated

Dan Johnson hit a pair of two-run homers Wednesday night, leading the Tampa Bay Rays to a 4-3 victory over the New York Yankees and back into first place in the AL East.

The teams with the baseball's top two records flip-flopped positions in the standings for the third straight night. The first two games of the important series went extra innings, with the Rays winning 1-0 on Monday and the Yankees regaining the division lead by a half-game with an 8-7 win on Tuesday.

The finale was filled with plenty of drama, too, even though the Yankees and Rays are far from finished. They'll play four more games in New York next week, with Tampa Bay holding an 8-6 edge in the season series.

Both of Johnson's homers came off Phil Hughes (16-8), who retired two of Tampa Bay's most dangerous hitters — Carl Crawford and Evan Longoria — before giving up a two-out single to Matt Joyce and Johnson's second homer of the night in the seventh.

The Yankees had taken a 3-2 in the top of the seventh on Curtis Granderson's two-run homer off Chad Qualls (1-0).

Randy Choate and Grant Balfour worked a scoreless eighth for the Rays. Rafael Soriano pitched the ninth, earning his franchise record-tying 43rd save in 46 opportunities by striking out Alex Rodriguez on three pitches with the potential tying run on base.

Rays starter James Shields scattered eight hits over 6 1-3 innings, walked two and struck out eight before departing with a 2-1 lead Johnson gave Tampa Bay with his two-run homer off Hughes in the fifth. Johnson has five homers since being called up last month from Triple-A Durham, where he was the International League MVP with 30 homers and 95 RBIs.

The Yankees went back on the top in seventh after plate umpire Lance Barksdale — over the objections of the Rays — ruled that Qualls' first pitch struck Derek Jeter on the left arm and Granderson followed with his 18th homer.

Tampa Bay manager Joe Maddon argued unsuccessfully that the ball hit Jeter's bat, eventually drawing an ejection from Barksdale.

Although it will take a major collapse for either team to not make the playoffs, the Yankees and Rays value the division title because of the homefield advantage that comes with it in the postseason.

Shields has struggled against the Yankees much of his career, going 1-7 with a 6.00 ERA in nine starts against them before this season. He's been much more effective this year, going 2-0 and outpitching CC Sabathia in a 3-0 victory at Tropicana Field on Aug. 1.

The Yankees had at least one hit in five of the first sixth innings, but were 2 for 7 with runners in scoring position against Shields — with both of the hits coming in the first, when Mark Teixiera's infield single sent Jeter to third and Robinson Cano's single to left scored the Yankees captain.

Hughes, who retired 12 in a row to start the game, allowed four runs and six hits over 6 2-3 innings. He walked none and struck out five.

Notes: Maddon reiterated before the game that he had no problem with Crawford's much-debated decision to tag up and try to advance to third base on a fly ball in the 10th inning Tuesday night. The speedy All-Star outfielder — the potential tying run — was thrown out by rookie Greg Golson, completing a game-ending double play. ... Yankees LHP Andy Pettitte, sidelined since June 19 by a strained left groin, is set to rejoin the rotation next Wednesday against Tampa Bay. RHP Javier Vazquez will shift into a long relief role. ... Yankees OFs Nick Swisher (left knee) and Brett Gardner (right wrist) remained out of the starting lineup. They could return this weekend.