Stocks mostly inched higher Friday after energy companies clawed back some of their sharp losses from earlier in the week.

The Standard & Poor’s 500 rose 0.16 percent to 2,438.30. The Dow Jones industrial average slipped 2.53 points to 21,394.76, and the Nasdaq composite gained 0.46 percent to end at 6,265.25.

advertisement | advertise on newsday

More than twice as many stocks rose than fell on the New York Stock Exchange.

Energy stocks led the way, and those in the S&P 500 climbed 0.8 percent for the largest gain of the 11 sectors that make up the index.

Rising prices for oil and natural gas drove the gains. Benchmark U.S. crude added 27 cents to settle at $43.01 per barrel. Brent crude, the international standard, rose 32 cents to $45.68, and natural gas rose 4 cents, or 1.2 percent, to $2.92 per 1,000 cubic feet.

Friday’s gains, though, weren’t enough to keep energy stocks from closing out their worst week in nine months. They had earlier sunk four straight days as oil dropped to its lowest price since August on expectations that the world has more crude supplies than users need. Energy stocks lost 2.9 percent over the course of the week.

What kept broad indexes afloat for the week were big gains for health care and technology stocks. The S&P 500 rose 0.2 percent for the week. — AP