- The Associated Press

BOSTON – David Ortiz hit a game-ending three-run homer, lifting the Boston Red Sox to a 6-3 victory over the Texas Rangers on Thursday night after Boston trailed by three runs.

Jacoby Ellsbury scored the tying run on a fielder’s choice in the seventh inning of his first game after sitting out five straight because of a groin injury.

Jonny Gomes led off the ninth with a double to center off Michael Kirkman (0-2), and Dustin Pedroia was walked intentionally to set up a potential double play with Ortiz coming to the plate.

Ortiz then drove the first pitch he saw from Kirkman for his 11th career walkoff homer into an empty Texas bullpen.

Ortiz watched his homer for a few moments before trotting his way toward home, where he was met by a swarm of celebrating teammates.

Andrew Bailey (2-0) pitched a scoreless ninth for Boston, which took two of three from Texas.

Ellsbury had a pair of doubles and two singles. Gomes also had four hits and Pedroia hit a two-run double in the third.

Jeff Baker and Adrian Beltre drove in all of Texas’ runs on early homers off of Jon Lester.

Texas led 3-2 until Ellsbury scored in the seventh when Mike Napoli beat out the throw on a fielder’s choice grounder that would have ended the inning after Boston loaded the bases with one out. Napoli hit a sharp grounder to first baseman Lance Berkman, who bounced his throw to Elvis Andrus covering second.

Jon Lester survived a rocky first few innings and pitched through the sixth for Boston, leaving with the Red Sox trailing 3-2 on Baker’s two-run homer in the second and a solo shot by Beltre in the third.

Boston got two back with two outs in the third when Pedroia doubled off the center field wall after Jose Iglesias reached on a walk and Ellsbury singled.

TIGERS 5, RAYS 2: Max Scherzer struck out nine in seven innings to remain unbeaten, and host Detroit took two of three against Tampa Bay.

Roberto Hernandez (3-6) allowed four runs in 51/3 innings, including a two-run homer by Detroit’s Victor Martinez. Evan Longoria struck out three times against Scherzer.

ORIOLES 3, ASTROS 1: J.J. Hardy got a season-high four hits and Adam Jones added an RBI double, leading Miguel Gonzalez and Baltimore to a win at Houston.

Gonzalez (3-2) yielded five hits and a run in six innings, and matched his season-best with seven strikeouts. He slowed down the Astros a day after they hit six home runs in an 11-7 win.

ROYALS 7, TWINS 3: Lorenzo Cain hit a two-run homer during a four-run eighth inning, and host Kansas City won back-to-back games for the first time since May 4-5.

ATHLETICS 5, WHITE SOX 4: Adam Rosales hit a two-out homer in the top of the 10th inning, and Oakland had a season-high four home runs in a win over host Chicago.

NATIONAL LEAGUE

CARDINALS 12, DIAMONDBACKS 8: Shelby Miller hit his first career home run and also pitched six sharp innings, leading host St. Louis over Arizona.

Matt Adams and Daniel Descalso homered in an eight-run fourth inning off Ian Kennedy. Matt Holliday and Matt Carpenter also connected for the Cardinals.

PHILLIES 5, BREWERS 1: Delmon Young homered, Tyler Cloyd allowed four hits over 62/3 scoreless innings, and visiting Philadelphia moved above .500 for the first time this season with its fifth straight victory.