By Lewis Krauskopf

(Reuters) - Wall Street retreated on Friday as lower oil prices weighed on energy shares and Facebook and Apple declined, but major indexes still posted gains for the week.

Energy <.SPNY> was the worst-performing major S&P sector, dropping 1.3 percent. Oil prices tumbled 4 percent on signs Saudi Arabia and Iran were making little progress on a bilateral agreement ahead of talks by crude exporters aimed at freezing production.

Facebook <FB.O> shares fell 1.6 percent and were one of the biggest drags on the S&P 500. The Wall Street Journal reported that the social media company overestimated viewing times for video ads.

Even so, the S&P 500 recorded its best weekly performance in more than two months. Stocks were given a boost on Wednesday when the U.S. Federal Reserve decided to keep rates steady, leaving intact the low-interest-rate environment that has helped fuel the bull market.

"I just think after a few strong days and a little weakness in energy that folks are taking some profit before the weekend," said Gary Bradshaw, portfolio manager with Hodges Capital Management in Dallas. "I just feel like the market is going to keep grinding higher."

The Dow Jones industrial average <.DJI> ended down 131.01 points, or 0.71 percent, at 18,261.45, the S&P 500 <.SPX> lost 12.49 points, or 0.57 percent, to 2,164.69 and the Nasdaq Composite <.IXIC> dropped 33.78 points, or 0.63 percent, to 5,305.75.

For the year, the benchmark S&P 500 is up about 6 percent. With the highly anticipated Fed decision now past, investors are turning toward the upcoming corporate earnings season and U.S. presidential election, with the first debate on Monday.

"We have a lot of noise coming in with the end of the quarter and the debate," said Bucky Hellwig, senior vice president at BB&T Wealth Management in Birmingham, Alabama. "But given what the Fed has done, I think we have volatility with a bias to the upside."

Nine of 11 major S&P sectors ended lower. The tech sector <.SPLRCT> fell about 1 percent, with Apple shares <AAPL.O> down 1.7 percent on concerns about iPhone sales.

Twitter <TWTR.N> shares surged 21 percent on reports that the microblogging company had initiated talks with several technology companies to explore selling itself.

Endo International <ENDP.O> shares jumped over 15 percent after the drugmaker announced a new chief executive.

Declining issues outnumbered advancing ones on the NYSE by a 2.13-to-1 ratio; on Nasdaq, a 1.67-to-1 ratio favored decliners.

The S&P 500 posted seven new 52-week highs and one new low; the Nasdaq Composite recorded 88 new highs and 13 new lows.

About 6.3 billion shares changed hands on U.S. exchanges, below the 6.9 billion daily average for the past 20 trading days, according to Thomson Reuters data.

(Additional reporting by Tanya Agrawal in Bengaluru, editing by G Crosse)