A rebound in the price of oil and natural gas Friday helped drive sharp gains for energy and financial companies, nudging U.S. stocks mostly higher.

That offset a slide in the technology sector following disappointing earnings from Microsoft, Google parent Alphabet and other big names.

advertisement | advertise on newsday

After a day of waffling, 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.

At the close on Wall Street, the Dow had gained 21.23 points, about 0.1 percent, to 18,003.8. The S&P 500 index added 0.10 points to 2,091.6. The Nasdaq composite index lost 39.7 points, about 0.8 percent, to 4,906.2.

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.

The U.S. benchmark price of crude oil rose 55 cents, about 1.3 percent, to $43.73 a barrel on the New York Mercantile Exchange. In London, the price of Brent crude, the international standard, rose 63 cents, about 1.4 percent, to $45.16.