A power outage at the Superdome early in the second half stopped America's biggest sporting event for more than half an hour and threatened to rob the Ravens of their momentum, having just established a 22-point lead.
After the interruption, the 49ers stormed back, cutting the deficit to just two points but Baltimore hung on as San Francisco came so close to the go-ahead score. The 49ers had first-and-goal in their final drive, trailing by five points, but quarterback Colin Kaepernick could not connect with a receiver.
The Ravens gave away a safety to run down the clock, making it 34-31 and while San Francisco had one last chance on the subsequent kick-off return, returner Ted Ginn Jr. was quickly swallowed up by Ravens tacklers, sparking celebrations by Baltimore players and staff.
Ravens quarterback Joe Flacco was voted the game's MVP, throwing three first-half touchdown passes, while Jacoby Jones returned the second-half kickoff 108 yards, a Super Bowl record.
Flacco's superb first half and Jones' return gave Baltimore a 28-6 lead, and with no team in Super Bowl history having overcome a deficit of more than 10 points, the game looked in the Ravens' keeping.
But moments later, lights lining the indoor arena faded, making it difficult to see, and the game was stopped. For 34 minutes the showpiece event was at a halt, with some players sitting by the sideline, others on the field, while some tossed footballs and limbered up. Throughout, the cheerleaders went through their routines.
When action resumed, the momentum in the game suddenly switched. Kaepernick and the 49ers scored 17 consecutive points, getting as close as 31-29. However they could not get ahead and lost a Super Bowl for the first time, blemishing their previously perfect 5-0 record and remaining one short of Pittsburgh's record six titles.
The AFC champion Ravens, a franchise that moved from Cleveland to Baltimore 17 years ago, improved to 2-0 in the big game. They also won the championship in 2001, when linebacker Ray Lewis was voted the game's MVP. Lewis was not a major factor this time, but he was a center of attention, playing in the final game of his 17-year career.
As well as Lewis, it was a triumph for Baltimore coach John Harbaugh, who got the better of younger brother Jim, who led San Francisco in the first instance of brothers coaching against each other in the Super Bowl.
Still, the older brother didn't do it without a large dose of anxiety as San Francisco rallied.
"How could it be any other way It's never pretty. It's never perfect. But it's us,'' John Harbaugh said. "It was us today.''
First, Kaepernick threw a 31-yard touchdown pass to Michael Crabtree who turned and got past some lax defense to cut the deficit to 15 points midway through the third quarter.
Then, with 5 minutes left in the third quarter, Frank Gore swept around right end for a 6-yard TD run, making it 28-20.
San Francisco tacked on David Akers' 34-yard field goal to get within 28-23 after he missed from a longer distance but the Ravens fouled by running into the kicker. It was his third successful kick of the game after hitting from 36 and 27 yards in the first half.
About 2 minutes into the fourth quarter, rookie kicker Justin Tucker made a 19-yard field goal to stretch the Ravens' lead to 31-23. Not long later, Kaepernick's 15-yard run around the left side - the longest TD run by a quarterback in Super Bowl history - made it 31-29. His 2-point conversion pass intended for Randy Moss was incomplete.
A 38-yard field goal by Tucker made it 34-29 with 4:19 left in regulation. Kaepernick and the 49ers drove toward the endzone, but on fourth down, his fade pass toward Crabtree was incomplete, with Jim Harbaugh screaming, to no avail, on the sideline for a holding penalty.
Before the game began, with 100 million or so Americans expected to tune in on TV, a chorus of 26 children from Sandy Hook Elementary School in Newtown, Connecticut. - where 20 students and six adults were killed in a shooting rampage in December - sang "America the Beautiful,'' accompanied by "American Idol'' alum Jennifer Hudson. Grammy winner Alicia Keys performed the national anthem, while Beyonce was the main act in the half time entertainment.