A 31-yard field goal by Lawrence Tynes at a damp Candlestick Park sealed a hard-fought victory for the Giants, who last won the Super Bowl over the New England Patriots four years ago with an improbable run to the title as a wild card.
"I was so nervous today before the game just anticipating this kind of game," Tynes told reporters. "I'm usually pretty cool but there was something about tonight that I knew I was going to have to make a kick."
Giants coach Tom Coughlin tipped his hat to his team for the late Williams turnover, forced by Jacquian Williams and recovered by Devin Thomas.
"That play at the end of the game was unbelievable, just to give us a chance of winning," Coughlin said after the Giants' fifth straight victory on the road.
"Otherwise it was a defensive struggle and no team was able to really move the ball."
The Giants, who made the playoffs after winning the regular season finale three weeks ago, will face the American Football Conference champion Patriots in the National Football League's title game in Indianapolis on February 5.
For much of a wet and windy afternoon in their formidable fortress of Candlestick Park, the 49ers appeared likely to withstand everything the Giants threw at them.
The home team applied early pressure as steady drizzle enveloped the stadium before quarterback Alex Smith connected with tight end Vernon Davis for a 73-yard touchdown, sending the home crowd wild with delight.
Davis, hit with a personal foul for excessive celebration on a camera stage in the end zone, came close to straying out of bounds as he powered down the right side but the touchdown was upheld after the play was reviewed.
San Francisco's defense kept the Giants at bay for the rest of the first quarter but New York responded early in the second, Eli Manning hitting fullback Bear Pascoe with a short pass to the right for a touchdown to cap a 10-play drive over 69 yards.
Both teams were defending tightly but, with Manning finding his groove, the Giants advanced 51 yards in 10 plays before edging ahead 10-7 just before half-time when Tynes kicked a 31-yard field goal.
Smith was sacked early in the third quarter but, after the 49ers had again cramped the Giants offense, he hit Davis for a 28-yard touchdown in the left corner for a 14-10 lead.
San Francisco carried that lead into the final quarter and stayed in control with their bruising defense before the fumble by Williams, hit on his knee by the bouncing ball after a Giants punt, led to a turnover.
New York took advantage as Manning's laser-like arm finally found wide receiver Mario Manningham for a 17-yard touchdown after a superbly orchestrated six-play drive.
A 25-yard field goal by 49ers kicker David Akers leveled the score at 17-17 with 5:43 left before the game spilled into nerve-jangling overtime and sudden-death.
"We knew it was going to be a tough game against this defense," said Manning, who was sacked six times and completed 32-of-58 passes for 316 yards and two touchdowns.
"We hit a couple big plays and the receivers stepped up and had some great plays and played tough all game."
Sunday's win gave Manning five career road playoff victories, the most of any NFL quarterback, and put Tom Coughlin into a tie for the most by a coach with seven.
(Editing by Frank Pingue and John O'Brien)