NEW YORK (WFAN/AP) — The Yankees were oh-so-close to sending the Red Sox out of town without the wild card lead.

But about eight hours after hitting two homers that didn’t help their cause, Jacoby Ellsbury put Boston in control of the race with another. His two-out, three-run homer in the 14th inning of the nightcap of a split doubleheader lifted the Red Sox over the Yankees 7-4 Sunday.

READ MORE: Gov. Murphy Expected To Mandate Masks In New Jersey Schools This Fall For All Students K-12

The Red Sox rallied from a 3-0 deficit to snap a four-game skid and head into their final three games with a one-game lead over Tampa Bay.

Boston held a nine-game lead over the Rays entering play Sept. 4 but has gone 5-16 since then. Up by 1½ games to start the day, the Red Sox nearly wasted that entire lead after losing the opener — which started at 1:11 p.m. — 6-2 despite Ellsbury’s two home runs. Combined with the Rays’ 5-2 win over Toronto, the Red Sox went into the second game with a half-game lead.

“We just put ourselves in a good position, that’s all we can do,” Ellsbury said after the game that ended 11:43 p.m.

It made it a lot easier for Boston’s rookies to wear lingerie and costumes for their trip to Baltimore.

Tampa Bay hosts the Yankees, who already have clinched the AL’s best record and home-field advantage through the ALCS.

“It was a BIG win, but we’ve got to go down tomorrow and play well,” Red Sox manager Terry Francona said.

Yankees manager Joe Girardi chose not to use Derek Jeter or Alex Rodriguez in the night game.

“If you ask them to get loose and they pull something, you know, they’ve been sitting a long time. People are really going to question what you do,” Girardi said. “Their bodies were shut down from 4 o’ clock. It’s 11:30 at night and I just don’t think it’s the right thing to do.”

Ellsbury homered off Scott Proctor (0-2) after Darnell McDonald singled and Marco Scutaro walked.

Franklin Morales (1-1) pitched two innings for the win. Felix Doubront, recalled on Sept. 1, finished the 5-hour, 11-minute game for his first save since August 2010.

In the opener, A.J. Burnett made his most impressive start in nearly three months and Jorge Posada hit a two-run homer for the Yankees. Ellsbury connected twice to become the first player in Red Sox history to reach 30 homers and 30 stolen bases in a season.

Desperate for a win in the second game, Francona used Jonathan Papelbon for a season-high 2 1-3 innings, bringing the closer in with the score tied on the road.

“We’ve got to grind and shine,” Papelbon said. “That’s what we’ve got to do from here on out.”

Typical of the bumbling baseball they’ve played while going 6-18 in September, the Red Sox made three more errors Sunday. Among them were several miscues on the basepaths and they blew an opportunity to advance the runner in the 10th inning with a sacrifice. Boston had the leadoff runner reach in each inning from the sixth through the 10th in the nightcap.

The Red Sox turned it around after a rough first inning. The Red Sox allowed only two hits after the second inning. Second baseman Dustin Pedroia made a spectacular grab in the 13th inning and the Red Sox got the clutch hit in the end.

READ MORE: 2 MTA Bus Passengers Struck By Stray Bullet When Gunfire Erupts In Queens

“It’s awesome,” Pedroia said. “A lot of people were writing us off so we’re going to play hard.”

Yet they still won.

Girardi was ejected for the third time this season when he raced onto the field in the 13th to protect first baseman Nick Swisher and dispute a call after Tim McClelland called Perdroia safe. Replays showed the diving Pedroia was out.

The Red Sox fell behind in the first inning for the third straight game in New York, but rallied to take a 4-3 lead in the seventh.

The Yankees tied it, though, in the bottom half on a sacrifice fly by Chris Dickerson, the only New York player to start both games.

The Red Sox fell behind in the first, making their third error of the doubleheader and 17th in 12 games.

With two on against John Lackey, Mark Teixeira hit a drive off the top of the fence in right-center. Teixeira went for third on the throw home and was able to score when catcher Jason Varitek threw the ball into left field.

After the game, an angry Lackey said a member of the media sent him a text message about 30 minutes before the game with personal information. He wouldn’t say who sent it or what it was about.

“It was unbelievable I got to deal with this,” Lackey said before ending his conversation with reporters.

The offense, meanwhile, woke up in the fifth after going 6 for 30 in the opener. Jed Lowrie hit a drive that hit off the wall in right field under the glove of a leaping Swisher for a triple. J.D. Drew, playing for the first time since July 19 because of a shoulder injury, singled him home for the first run off Ivan Nova in 15 innings.

Adrian Gonzalez’s RBI single and Scutaro’s run-scoring double tied it in the sixth, and Varitek singled for a 4-3 lead in the seventh.

In the opener, the Yankees raced to a 2-0 lead behind two bunt singles and some poor play by the Red Sox. Catcher Jarrod Saltalamacchia had an error and a passed ball. Carl Crawford made an error in left field that led to a run in the fifth.

Tim Wakefield (7-8) pitched four-plus innings, giving up five runs — three earned — five hits and five walks.

Batting fourth for the first time since 2009, Posada connected in the third inning for his fifth homer against the knuckleballer. The 40-year-old with a diminished role this year was given a curtain call.

Burnett (11-11) allowed five hits — three to Ellsbury — and two runs in 7 2-3 innings, his first outing of more than six innings since he went eight on July 29.

Jeter had three hits to lift his average to .300 at the end of the game for the first time since April 2. Starting with July 9, the day he reached 3,000 hits, he is batting .346 following a .257 start.

MORE NEWS: New York State Assembly Gives Cuomo 1 Week To Defend Himself In Sexual Harassment Investigation

(TM and Copyright 2011 CBS Radio Inc. and its relevant subsidiaries. CBS RADIO and EYE Logo TM and Copyright 2011 CBS Broadcasting Inc. Used under license. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed. The Associated Press contributed to this report.)