Super Bowl XLVII was on the line that day, and the Ravens held on for a 34-31 victory.
This time, the 49ers and Ravens entered the game with matching 1-4 records and were fighting just to keep their fading playoff hopes alive.
The 49ers prevailed as quarterback Colin Kaepernick passed for a season-high 340 yards and two touchdowns in a 25-20 victory at Levi's Stadium.
Ex-Ravens wide receivers Anquan Boldin and Torrey Smith faced their former team for the first time and had big games, helping the 49ers snap a four-game losing streak. Boldin caught five passes for 102 yards, and Smith caught three passes for 96 yards and a 76-yard touchdown. Fullback Bruce Miller added three catches for 89 yards.
The 49ers (2-4) pulled to within two games of first-place Arizona in the NFC West and can move even close Thursday night at Levi's with a victory over Seattle.
"You understand what's at stake," Smith said. "The more you win the better position you're going to be in. We just need to try to figure out a way to win the next game. We can't really look too far ahead. We aren't in any position to even think about doing that with our record."
Kaepernick completed 16 of 27 passes with no interceptions. Ravens quarterback Joe Flacco completed 33-of-53 passes for 343 yards and two touchdowns but was intercepted twice.
"It all starts with me not making those mistakes," Flacco said. "We can't afford to do that right now. We have to go out there and play fundamental football, take care of the football, and when the plays present themselves, we've got to make them. We weren't able to do that. I didn't play smart."
Baltimore wide receiver Steve Smith Sr. caught seven passes for 137 yards and one touchdown.
The 49ers built a 16-6 halftime lead and made it 19-6 with 7:34 left in the third quarter when Phil Dawson drilled a 42-yard field goal.
Baltimore (1-5) responded with a touchdown, Flacco hitting Smith Sr. on a 24-yard scoring strike with 2:39 remaining in the third.
The Ravens forced a quick punt and drove into 49ers territory but stalled at the 27, and Justin Tucker missed a 45-yard field goal attempt early in the fourth quarter.
San Francisco then drove 65 yards in five plays for a touchdown, Kaepernick hitting wide receiver Quinton Patton with a 21-yard scoring strike to give the 49ers a 25-13 lead. Their two-point try failed. Three plays before his touchdown pass, Kaepernick fired a 51-yard pass to Boldin, giving the 49ers a first down at the Baltimore 28.
"Our team is building where we're gradually picking up momentum, we're playing better and better," Kaepernick said.
Baltimore closed the gap to 25-20 with 5:14 left to play when Flacco fired a 2-yard touchdown pass to wide receiver Kamar Aiken on fourth-and-goal. The Ravens drove 80 yards in 14 plays for the score.
The Ravens appeared to have forced a 49ers punt, but cornerback Jimmy Smith was flagged for holding on third-and-6 from the San Francisco 40 with 2:26 to play.
Baltimore's final drive ended when Flacco's third-and-five pass from the 49ers' 35 to Smith was broken up in the end zone as time expired. The Ravens lost for the fifth time by six or fewer points.
"Obviously not good enough," Ravens coach John Harbaugh said. "Didn't play well enough. Way too many mistakes."
The 49ers took a 3-0 lead with 7:00 left in the first quarter on Dawson's 53-yard field goal, capping a five-play, 32-yard drive. They extended their lead to 6-0 when Dawson hit from 31 yards with 3:30 remaining in the first.
Baltimore answered with Tucker's 22-yard field goal with 13:16 left in the first half.
Two plays later, Kaepernick hit Smith with a 76-yard touchdown pass. Lined up right on second-and-six, Smith got behind former 49ers cornerback Shareece Wright down the right sideline, and Kaepernick hit him in stride.
Wright signed during the offseason with the 49ers as a free agent but never suited up for a game and was released on Oct. 10. Ravens starting left cornerback Lardarius Webb (thigh) was inactive, and backup Kyle Arrington sustained a leg injury in the first quarter, forcing Baltimore to use Wright.
"When you have a guy on your team for that long and get to see him every day in practice, you understand his weaknesses, as well as his strengths," Boldin said of Wright. "That was one of the things that we wanted to attack."
Wright owned up to his mistake.
"This was my first game as part of this defense, and I gave up a big play," Wright said. "I know that's on me, and I'll take ownership on that. I can't lie about that. It was perfectly-executed, but I've got to stay on top of that and not be too aggressive."
The 49ers increased their lead to 16-3 on Dawson's 26-yard field goal with 8:04 left in the half, and Tucker hit from 36 yards with 4:14 remaining.
NOTES: 49ers RB Reggie Bush (calf) and WR Bruce Ellington (calf) were inactive. ... Ravens starting DE Chris Canty (calf) was inactive for the fourth straight game. ... 49ers TE Vernon Davis (knee) returned to the lineup after missing two games. ... Ravens RB Justin Forsett (ankle), WR Steve Smith Sr. (back) and TE Crockett Gillmore (calf) had been listed as questionable but were active for the game.