(CNN) — Ray Lewis had to wait a half hour, but the Raven got the swan song he wanted.
The renowned linebacker, considered by many to be one of the greatest to ever play the game, went out a winner, as the Baltimore Ravens beat the San Francisco 49ers 34-31 in a Super Bowl delayed by a third-quarter power outage.
"What better way to go out," Lewis said. "The things that we have been through all year, we were battle tested through this journey, the up and down roller coaster, the injuries, the passings of people. We stayed together, and now I get to ride off into the sunset with my second ring."
The Ravens took a 22-point lead before the 49ers, after a 35-minute delay for a power failure, rallied. San Francisco got within two points, but Baltimore held on.
"We talk to our guys all the time, it's never very pretty, it's never perfect but it is us," Baltimore coach John Harbaugh said.
It is the second victory in the NFL championship for the Ravens, who also won Super Bowl XXXV.
The power in about half of the Superdome went off with 13:22 left in the third quarter and the Ravens leading 28-6. The referee called a halt to the game while stadium officials worked to fix the problem. At about 8:45 p.m. ET, power was restored and the process of powering up the lights began.
The game restarted after a 35-minute delay, according to CBS, which broadcast the game.
The break helped the 49ers, who scored three times in just over four minutes.
The 49ers scored their first touchdown when Michael Crabtree scored on a 31-yard touchdown throw from Colin Kaepernick. That made the score 28-13 with 7:20 left in the third quarter.
Three minutes later, Frank Gore scored on a six-yard run off the right side to draw the 49ers to within eight, after a David Akers' extra point.
After a Ray Rice fumble gave the ball back to the 49ers, Akers kicked his third field goal of the contest.
"I felt our guys battled, they competed," losing coach Jim Harbaugh said. "We got a spark, and we weren't going to look back. It was a heck of a football game."
Rookie Justin Tucker boosted the Ravens lead back to eight points with a field goal 2:03 into the final quarter.
But the Niners answered quickly. Kaepenick's 15-yard scamper -- the longest touchdown run by a quarterback in Super Bowl history -- made the score at 31-29 with 9:57 left in regulation. But his throw on the two-point conversion was too high.
Tucker kicked a 38-yard field goal with 4:23 left in the game to make it 34-29.
The 49ers drove to the Ravens' five-yard line but Kaepernick's lofted pass to Crabtree sailed out of bounds with 1:49 remaining. Jim Harbaugh pleaded with the officials to call a hold on the Ravens' defensive back, but they saw no penalty.
After running three plays, the Ravens took a safety with four seconds left in the game instead of punting out of their end zone.
The 49ers ran out of time as they returned the game-ending free kick.
The Harbaugh brothers met at midfield after the game.
"I told him I was proud of him" Jim Harbaugh said. "I think he said the same."
Ravens' quarterback Joe Flacco -- who was selected as the game's most valuable player -- was 22 of 33 for 287 yards. Kaepernick was 16 of 28 for 246 yards.
Flacco threw red-zone touchdown passes in the first half -- the first to Anquan Boldin and another to Dennis Pitta.
He also hit Jones for a 56-yard touchdown pass, where the wide-open receiver fell down catching the ball at the 8-yard line, got up and evaded one defender before sprinting into the end zone.