NEW ORLEANS — An electrical outage nearly powered the San Francisco 49ers to an improbable comeback victory against the Baltimore Ravens in Super Bowl XLVII.

But in the end, the Ravens saw the light and held on for a dramatic 34-31 victory Sunday at the Mercedes-Benz Superdome.

Rallying from a 28-6 deficit early in the third quarter, the 49ers’ came out a changed team after a 35-minute delay. From that point forward, the momentum belonged to the 49ers, who closed within 31-29 with 10 minutes left and threatened to take the lead inside the final two minutes.

But San Francisco failed to get in the end zone from first-and-goal at the Ravens’ 7, and Baltimore survived the final frenetic seconds to earn their second world championship in franchise history.

“I thought we battled to the brink of winning,’’ 49ers coach Jim Harbaugh said.

“We thought we were going to win,’’ said 49ers tight end Vernon Davis, who had six catches for 104 yards. “That’s just the way to be. You have to believe, and we did. I think we did a terrific job as far as trying to keep our composure, stay under control and make plays.’’

Ravens quarterback Joe Flacco was named the game’s MVP, outdueling 49ers quarterback Colin Kaepernick, and in all probability earning a long-term contract worthy of a Super Bowl champion in the coming months.

Kaepernick played well in his 10th NFL start, accounting for 364 yards from scrimmage and two touchdowns. He completed 16 of 28 passes for 302 yards and one touchdown and rushed seven times for 62 yards and another touchdown.

“(Kaepernick) does what he always does,’’ 49ers cornerback Chris Culliver said. “He’s the man.’’

The night began with the pregame coin flip at midfield featuring a memorable staredown between Ravens rush linebacker Terrell Suggs and 49ers running back Frank Gore. Suggs kept his eyes trained on his shorter adversary, who nervously rocked back and forth but never looked up.

No handshakes were exchanged when the captains broke for their respective sidelines, setting the tone for what turned out to be 60 bruising minutes of football.

Because of the 35-minute delay, the sellout crowd unexpectedly was treated to two different games.

The Ravens held a 28-6 lead with 13:21 remaining in the third quarter and were seemingly in command thanks to Jacoby Jones’ NFL-record-tying 108-yard kick return for a touchdown to open the second half.

Then the outage forced both teams to power down.

When play resumed, Kaepernick helped the 49ers roar back into contention with a 17-point flurry to trail 28-23 after three quarters. Kaepernick connected on a 31-yard touchdown pass to wide receiver Michael Crabtree, Gore scored on a 6-yard run, and David Akers kicked a 34-yard field goal to cut the deficit to 28-23 and set the stage for a thrilling stretch run.

“We got a spark (after the outage), and we weren’t going to look back after that,’’ Harbaugh said.

Kicker Justin Tucker gave the Ravens more breathing room at 31-23 with a 19-yard field goal at the 12:54 mark of the fourth quarter, but the 49ers wouldn’t go away.

Kaepernick made it 31-29, scrambling out of trouble and tight-roping down the left sideline for a 15-yard touchdown. Going for the tie, Kaepernick’s two-point pass attempt fell incomplete.

Tucker’s 38-yard field goal and a 49ers’ safety closed out the scoring. In between, the 49ers made it interesting, driving to a first-and-goal at the Ravens’ 7-yard line. But Kaepernick and Crabtree failed to connect on three consecutive plays from the 5 to doom the 49ers’ comeback hopes.

“It was like we were trying to feel them out at the beginning and it took too long, especially with a team like that,’’ said 49ers defensive lineman Ricky Jean Francois, who starred on LSU’s 2007 BCS national championship team.

“We knew we could get the ball rolling, and that’s what we did. We have that gear, but we have to learn in the future that won’t always save us.’’