A rebound in the price of oil and natural gas helped drive sharp gains for energy and financial companies, nudging U.S. stocks mostly higher Friday.
That offset a slide in the technology sector following disappointing earnings from Microsoft, Google parent Alphabet and other big names.
The Dow Jones industrial average eked out a tiny gain, while the Standard & Poor's 500 index closed essentially flat. Both ended the week higher. But the tech-heavy Nasdaq composite fell short on both counts.
"The Nasdaq took a hit today," said Erik Davidson, chief investment officer at Wells Fargo Private Bank.
The Dow rose 21.23 points, or 0.1 percent, to 18,003.75. The S&P 500 index added 0.10 points to 2,091. The Nasdaq composite index lost 39.66 points, or 0.8 percent, to 4,906.23.
Trading was listless for much of the day, with the Dow and S&P 500 wavering between small gains and losses as the Nasdaq stayed in the red.
As was the case much of the week, investors were mostly focused on company earnings and energy prices.
The latter helped lift several oil and gas companies.
Southwestern Energy notched the biggest gain in the S&P 500. The stock vaulted $1.60, or 15 percent, to $12.27. Range Resources jumped $2.58, or about 7 percent, to $39.75, while Chesapeake Energy climbed 36 cents, or 5.8 percent, to $6.55.
Benchmark U.S. crude rose 55 cents, or 1.3 percent, to close at $43.73 a barrel in New York. Brent crude, used to price international oils, gained 58 cents, or 1.3 percent, to close at $45.11 a barrel in London. Natural gas gained 7 cents, or 3.5 percent, to close at $2.14 per 1,000 cubic feet.
Investors cheered earnings from Norfolk Southern, which jumped 10.5 percent after the railroad operator slashed costs during its latest quarter. The stock rose $8.70 to $91.33.
Quarterly results from several big-name companies failed to impress traders, however.
American Airlines Group fell 4.5 percent after the company said weaker fares and labor costs cut into its revenue in the first quarter. The stock shed $1.80 to $38.21.
Investors sold shares in Starbucks after the coffee chain reported disappointing sales growth for the first three months of the year. The stock lost $2.96, or about 5 percent, to $57.68.
Microsoft fell 7.2 percent, making it the biggest decliner in the S&P 500. The stock lost $4 to $51.78, while Alphabet slid $42.23, or 5.4 percent, to $737.77. Overall, the technology sector was off about 2 percent.
Despite the declines, investors seemed to conclude that the issues driving lackluster results at Alphabet and Microsoft were largely confined to those companies, Davidson said.
"The broader market doing better," he said. "Energy has to be part of that."
Major stock indexes in Europe ended lower.
Germany's DAX fell 0.6 percent, while France's CAC 40 slipped 0.3 percent. Britain's FTSE 100 declined 1.1 percent. In Asia, Hong Kong's Hang Seng index fell 0.7 percent. Tokyo's Nikkei 225 rose 1.2 percent. Seoul's Kospi slid 0.3 percent and Sydney's S&P ASX 200 lost 0.7 percent.
In other energy futures trading, wholesale gasoline added about a penny to close at $1.53 a gallon. Heating oil also rose a penny to close at $1.31 a gallon.
Precious and industrial metals futures were mixed. Gold fell $20.30, or 1.6 percent, to $1,230 an ounce, silver slid 19 cents, or 1.1 percent, to $16.90 an ounce and copper rose about a penny to $2.26 a pound.
Bond prices fell. The yield on the 10-year Treasury note rose to 1.89 percent from 1.86 late Thursday.
In currency markets, the dollar gained to 111.67 yen from Thursday's 109.53 yen. The euro fell to $1.1245 from $1.1295.