BOSTON — Mookie Betts lined a two-run double off the left-field wall with two outs in the ninth inning, capping a three-run rally that lifted the Boston Red Sox to a 5-4 win over the St. Louis Cardinals on Wednesday night.

Xander Bogaerts hit a solo homer for the AL East-leading Red Sox, who won for the 12th time in 14 games and maintained their 41/2-game lead over the second-place New York Yankees.

Kolten Wong had three hits, including an RBI single in St. Louis’ four-run second inning, and Lance Lynn held Boston’s offense down with six solid innings before the Red Sox rallied.

It was just the third loss in 11 games for the Cardinals, who were swept in the two-game series, their first visit to Fenway Park since the 2013 World Series.

Cardinals Manager Mike Matheny was ejected by home plate umpire Chris Segal in a wild ninth inning. Trevor Rosenthal gave up Bogaerts’ homer into the Green Monster seats. Zach Duke (0-1) struck out a batter and walked one before John Brebbia gave up Betts’ hit, with Jackie Bradley Jr. beating a relay home with a headfirst slide for the winning run as catcher Yadier Molina dropped the throw.

Craig Kimbrel (5-0) pitched one hitless inning for the win.

Lynn allowed two runs – one earned – and seven hits, walking and striking out three.

Eduardo Rodriguez gave up four runs and eight hits in 51/3 innings.

The Cardinals jumped ahead 4-0 when Wong and Matt Carpenter sandwiched RBI singles around Luke Voit’s run-scoring double. Wong scored on Christian Vazquez’s passed ball.

Vazquez scored on a throwing error in the third when Lynn fired the ball wildly past first on Eduardo Nunez’s infield hit. Betts added his sacrifice fly.

NOTES: Manager John Farrell said LHP David Price (left elbow inflammation) rested after throwing Tuesday. … LF Andrew Benintendi returned to the lineup after getting hit by a pitch and leaving early Tuesday. …The Red Sox honored their 1967 AL champs – known as the Impossible Dream team. Led by Hall of Famer Carl Yastrzemski – a Triple Crown winner that season – there were 18 former players honored during an on-field pregame ceremony. It’s known as the team that triggered fan interest in Boston after years of small crowds. “I think we were the ones that sparked the fire and the fire is now ‘Red Sox Nation’ – and it’s great to be a part of that,” said Jim Lonborg, who won the ’67 Cy Young Award.