SEATTLE (AP) — Jean Segura rolled an RBI single up the middle with two outs in the 13th inning to cap a two-run rally and give the Seattle Mariners a 6-5 victory over the Boston Red Sox in a game that ended early Wednesday morning.

Mitch Haniger walked with one out in the 13th off Doug Fister (0-5), pitching his third inning, and was forced at second on Ben Gamel's fielder's choice. Guillermo Heredia, who had a three-run homer in the second, singled Gamel to third. Gamel scored on a wild pitch to tie it, with Heredia advancing all the way to third. Mike Zunino then walked. Shortstop Xander Bogaerts fielded Segura's roller behind second, but his off-balance throw was way late.

The Red Sox, who stranded two runners in the eighth, ninth and 11th innings, had taken a 5-4 lead in the top half when Sandy Leon singled home Hanley Ramirez with two outs off Tony Zych (5-2).

Mike Zunino opened the seventh inning with his 15th home run to bring Seattle even at 4-4.

The Red Sox capitalized on a sudden loss of command by starter Felix Hernandez for three runs in the sixth to erase a 3-1 deficit.

Highly touted prospect Rafael Devers, making his debut, walked to open the inning and Andrew Benintendi drew a one-out walk. Both runners advanced on a wild pitch and Dustin Pedroia followed with a two-run double. Pedroia advanced on Ramirez's flyout and came home on Bradley Jr.'s single to center.

Heredia's three-run homer off starter Drew Pomeranz staked the Mariners to a 3-0 lead in the second. Kyle Seager bounced a one-out single off the glove of second baseman Pedroia. Gamel drew a two-out walk and Heredia lined an 0-1 pitch over the wall in left for his sixth homer.

Ramirez cut it to 3-1 in the fourth with 17th home run, a two-out shot to left.

The 20-year-old Devers, who began the season at Double-A and then was called up Monday after just nine games at Triple-A Pawtucket, flied out to center in his first at-bat, walked, hit into a double play in the seventh, and walked again in the ninth. He struck out in the 11th to end the inning with the go-ahead run at third and flied out to center to end the 13th. He finished 0 for 4 with two walks.

UP NEXT:

Red Sox: LHP Chris Sale (12-4, 2.58) closes out the three-game series Wednesday afternoon. Sale has gone at least six innings in all but one of his 20 starts. He has not allowed an earned run in three of his last four starts. Sale leads the AL with 200 strikeouts.

Mariners: RHP Andrew Moore (1-2, 5.70) has not won in four starts since a victory in his debut on June 22. Moore, the Mariners' second-round pick in 2015, has allowed nine home runs in 30 innings.