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

The increase offset a slide in the technology sector after disappointing earnings from Microsoft and Alphabet, the parent of Google.

The Dow Jones industrial average managed a tiny gain, and the Standard & Poor’s 500-stock 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.