NEW YORK — Stocks advanced Friday, giving the Standard & Poor’s 500 Index its biggest weekly gain since July 2009, as retail sales beat economists’ estimates and the Group of 20 nations began discussions on Europe’s debt crisis.

The S&P 500 rose 1.7 percent, or 20.92 points, to 1,224.58, extending its weekly gain to 6 percent. It was the S&P’s highest close since Aug. 3, when Washington was paralyzed over raising the U.S. borrowing limit.

The Dow Jones industrial average added 166.36 points to close at 11,644.49, erasing its 2011 loss. The Nasdaq rallied 47.61 points, or 1.8 percent, to 2,667.85, also wiping out this year’s decline.

U.S. equities gained as retail sales rose more than forecast in September, easing concern that slumping confidence and scant hiring will derail the biggest part of the economy.

U.S. stocks also followed a rally in European shares as G-20 finance ministers began talks. Nations from China to Brazil are considering increasing the International Monetary Fund’s lending resources to help stem the European debt crisis, G-20 and IMF officials said.

Google shot up 5.8 percent to $591.68 after its quarterly income jumped 26 percent. Apple rose 3.3 percent to $422 as its new iPhone went on sale.

– The Associated Press and Bloomberg News contributed to this report.