Washington - Wall Street gained for a fourth straight session on Tuesday, its longest winning streak since January, buoyed by the energy sector as oil prices rebounded from early declines.
Oil prices were initially lower on concerns a deal between Iran and six global powers would result in more supply, but turned higher after it became apparent sanctions on Tehran's crude exports would not be removed immediately.
"The big news is clearly in the oil markets and the fact there was an agreement reached," said David Lefkowitz, senior equity strategist at UBS Wealth Management Americas in New York.
"There is still, frankly, a lot of uncertainty about exactly what it will do in terms of oil supply."
The S&P energy sector advanced 0.8%, led by a 0.8% gain in Exxon Mobil to $83.11. Brent settled up 1.1% to $58.51 and US crude settled up 84 cents to $53.04 a barrel.
Gains were broad, with nine of the 10 major S&P 500 sectors ending higher, led by a 1% gain in the healthcare index . The Nasdaq biotech index jumped more than 2% to hit a record high for the second time in three weeks.
The Dow Jones industrial average rose 75.9 points to 18 053.58, the S&P 500 gained 9.35 points to 2 108.95 and the Nasdaq Composite added 33.38 points to 5 104.89.
Investors have shifted focus to corporate profits as the pace of quarterly results begins to pick up speed, diverting attention from the debt crisis in Greece and the massive selloff in Chinese stocks.
US companies are expected to report their worst sales decline in nearly six years when they post second-quarter results, while earnings are expected to have fallen 2.8%, according to Thomson Reuters estimates.
JPMorgan and Wells Fargo helped lift financials by 0.4% after posting quarterly results. JPMorgan rose 1.4% to $69.04 and Wells Fargo climbed 0.9% to $57.25.
Twitter jumped as much as 8.5% after a false report, attributed to Bloomberg LP, that the social media company received an offer to be acquired for $31bn. Bloomberg and Twitter said the report was fake and the stock ended the session up 0.9% at $36.72.
Micron Technology jumped as much as 12.7% to $19.84 and was the biggest gainer on the S&P 500. China's state-backed Tsinghua Unigroup is preparing a $23bn bid for the US memory chip maker, Reuters reported, in what would be the biggest Chinese takeover of a US company.
NYSE advancing issues outnumbered declining ones 1 934 to 1 089; on the Nasdaq, 1 769 issues rose and 1 032 fell.
The S&P 500 posted 44 new 52-week highs and 2 new lows while the Nasdaq recorded 137 new highs and 34 new lows.
Volume was light, with about 5.5 billion shares traded on US exchanges, well below the 6.8 billion average so far this month, according to data from BATS Global Markets.