US stock indexes nudged higher today after energy companies clawed back some of their sharp losses from earlier in the week.
After meandering up and down through the day, the Standard & Poor's 500 rose 3.80 points, or 0.2%, to end at 2,438.30.
The Dow Jones industrial average slipped 2.53 points, or less than 0.1%, to 21,394.76, and the Nasdaq composite gained 28.56, or 0.5%, to 6,265.25.
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% for the largest gain of the 11 sectors that make up the index.
Rising prices for oil and natural gas drove the gains.
Benchmark US crude added 27 cents to settle at 43.01 US dollars per barrel.
Brent crude, the international standard, gained 32 cents to 45.54 dollars and natural gas rose four cents, or 1.2%, to 2.93 dollars per 1,000 cubic feet.
EQT, a producer of natural gas and crude, had the day's biggest gain in the S&P 500 and jumped 4.16 dollars, or 8%, to 56.19 dollars. Cabot Oil & Gas climbed 88 cents, or 3.8%, to 23.74 dollars.
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% 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% for the week.
Health care stocks climbed as the Senate unveiled its proposal to revamp how Americans get medical care.
Technology companies, meanwhile, are forecast to report strong growth in the upcoming earnings season, and Oracle's profit report on Wednesday sailed past analysts' expectations.
"In terms of the overall market, what you really worry about with oil is what it does to earnings," said Steve Chiavarone, portfolio manager at Federated Investors.
A big pickup in corporate profits has been one of the main reasons for the stock market's continued climbs this year, and energy companies had been forecast to provide some of the strongest growth in 2017.
With the price of oil about 15% below where it was a year ago, energy companies' profits may be at risk.
But as long as oil's price can hold close to where it is, "that's good enough given that there's corporate profit growth everywhere else", Mr Chiavarone said.
Friday's biggest decliner in the S&P 500 was Bed Bath & Beyond, which reported weaker earnings for the latest quarter than analysts expected.
The retailer's revenue also fell short of Wall Street's forecasts. Its shares fell 4.09 dollars, or 12.1%, to 29.65 dollars.
Bond prices were little changed, and yields held relatively steady.
The 10-year Treasury yield dipped to 2.14% from 2.15% late Thursday. The two-year yield was flat at 1.34%, and the 30-year yield held at 2.72%.
The dollar slipped to 111.26 Japanese yen from 111.34 yen late Thursday.
The euro rose to 1.1199 dollars from 1.1147 dollars, and the British pound rose to 1.2722 from 1.2672 dollars.
In European stock markets, France's CAC 40 fell 0.3%, Germany's Dax lost 0.5% and the FTSE 100 slipped 0.2%.
A monthly survey revealed that a measure of economic strength in the 19-country Eurozone slipped to a five-month low in June, which was below market expectations. However, the IHS Markit composite purchasing managers' index indicated that job creation and business confidence were still robust.
Japan's Nikkei 225 index added 0.1%, South Korea's Kospi rose 0.3% and the Hang Seng in Hong Kong was close to flat.
In the commodities market, gold rose seven dollars to settle at 1,256.40 dollars an ounce. Silver added 14 cents to 16.65 dollars per ounce, and copper rose three cents to 2.62 dollars per pound.
Heating oil was close to flat at 1.37 dollars per gallon and wholesale petrol was little changed at 1.43 dollars per gallon.