BALTIMORE — The Boston Red Sox celebrated a rare September victory for about 20 minutes before turning their attention toward their next game – the last and most important of the 162-game schedule.

The Red Sox maintained a share of the AL wild-card lead Tuesday night, using four home runs to beat the Baltimore Orioles 8-7 and set up a dramatic end to the regular season.

The Red Sox were 6-19 this month before rebounding to edge the last-place Orioles. The win, combined with Tampa Bay’s 5-3 win over the New York Yankees, kept Boston and the Rays tied with one game left.

After blowing a nine-game lead in 23 days, the Sox will start Jon Lester (15-9) against Baltimore tonight in an effort to get into the postseason for a fourth time in five years. Lester, Boston’s winningest pitcher, will throw on three days’ rest.

A month ago, the Red Sox would shudder at the prospect of a must-win situation on the final day. But here they are, and they intend to make the best of it.

“I think it’s really good for baseball, not so good for my stomach,” Manager Terry Francona said. “It’s exciting. If you don’t want to show up (tonight) and play, you’ve got no pulse. My goodness, I can’t remember being that nervous in a long time. Go back to the hotel and not sleep, then show up and see what we can do.”

Boston will look to put together its first winning streak since sweeping a doubleheader from Oakland on Aug. 27. If the Rays and Red Sox remain tied after tonight, Tampa Bay will host a one-game playoff Thursday.

“Everybody’s been watching the scoreboard and knowing that we need to win tonight so we can come back (Wednesday) and fight through it again,” David Ortiz of Boston said. “I hope if I’m still here next year we can make it easier. We’re playing like this is a playoff already.”

Rookie Ryan Lavarnway became the unlikeliest of heroes for Boston, hitting his first two major league homers after being thrust into the lineup because of injuries to catchers Jarrod Saltalamacchia (sore collarbone) and Jason Varitek (knee).

Lavarnway, a Yale philosophy major who never played a big league game before August, hit a three-run drive in the fourth inning and a solo shot for an 8-4 lead in the eighth.

“Besides what he did offensively, I thought he ran the game, I thought he had a lot of poise,” Francona said. “That was one of the more exciting things to watch. We’ve seen a lot of interesting things here over the years, but that was right near the top.”

Lavarnway said, “It feels good, but the job’s not done. We’ve still got to go out (tonight) and win another ballgame.”

Jacoby Ellsbury and Marco Scutaro also connected for Boston, which scored all its runs on home runs.

Alfredo Aceves (10-2) pitched 32/3 innings of three-hit relief for the Red Sox, who survived homers from Matt Wieters and Adam Jones.

After the Orioles scored twice in the eighth off Daniel Bard to make it 8-6, Jonathan Papelbon survived a hectic ninth for his 31st save. Wieters drove in a run with a grounder and Baltimore had the potential tying run at second with two outs before Jones grounded out on a 3-2 pitch.

“Everything we got, we needed,” Francona said. “We hung on for dear life.”

Said Jones: “We battled down to the final pitch. That’s the way I live. You know we ain’t going to quit.”

Pitching at Camden Yards for the first time since being traded by Baltimore to Seattle in February 2008, Boston starter Erik Bedard gave up three runs and five hits in 31/3 innings. He needed 84 pitches to get 10 outs.