Energy companies led US stocks to modest gains on Wednesday as the market recouped some of its hefty losses from the day before.
Big retailers and health care companies also helped lift the market, which was coming off its worst day in almost three weeks.
Utilities and phone companies did not have such a good day while some travel booking companies and airlines also fell.
"It's a little bit of a rebound from the sort of dramatic day yesterday after everybody got back from the long holiday weekend at the end of the summer and refocused on the market," said Lindsey Bell, investment strategist at CFRA Research.
"We've seen that through the past year, any time we've had some sort of dip, it's a buying opportunity for investors."
The Standard & Poor's 500 index rose 7.69 points, or 0.3%, to 2,465.54.
The Dow Jones industrial average added 54.33 points, or 0.3%, to 21,807.64.
The Nasdaq composite gained 17.74 points, or 0.3%, to 6,393.31.
The Russell 2000 index of smaller-company stocks picked up two points, or 0.2%, to 1,402.20.
The stock indexes are on pace to end the week lower, but are holding on to gains for the year.
The S&P 500 and Dow are both up just over 10%.
The Nasdaq is up 18.8%, while the Russell 2000 has gained 3.3%.
The market veered higher from the start of regular trading on Wednesday and held its course through much of the day.
News that President Donald Trump has agreed to a plan to fund the government and increase the nation's debt limit for three months helped lift the market.
"It reassured the market that Washington is on board with stabilising its financial responsibilities," Ms Bell said.
Tuesday's market jitters over the heated rhetoric between the US and North Korea appeared to ease somewhat on Wednesday, even as investors monitored Hurricane Irma.
The mammoth storm, which made its first landfall in the islands of the northeast Caribbean early Wednesday, seemed almost certain to hit the United States by early next week.
A day after spiking more than 20%, the VIX, a measure of how much volatility investors expect in stocks, fell nearly 5% on Wednesday.
And bond yields, which fell sharply a day earlier, rebounded modestly.
The yield on the 10-year Treasury note rose to 2.10% from 2.06% late on Tuesday.
Gold, which climbed on Tuesday to the highest level in more than a year, fell 5.50 to 1,339 dollars an ounce Wednesday.
Rising oil prices helped boost energy stocks.
Helmerich & Payne rose 2.58 dollars, or 5.9%, to 46.35 dollars. Marathon Oil added 44 cents, or 3.9%, to 11.73 dollars.
All told, benchmark US crude gained 50 cents, or 1%, to settle at 49.16 dollars a barrel on the New York Mercantile Exchange.
Brent crude, used to price international oils, rose 82 cents, or 1.5%, to 54.20 dollars a barrel in London.
Investors also bid up shares in several big retailers.
Gap shares surged 7.4% after the apparel retailer said it will shift its focus to its growing brands Old Navy and Athleta, and away from the Gap and Banana Republic.
The company said that it will close about 200 Gap and Banana Republic stores in the next three years and open about 270 Old Navy and Athleta stores during the same period.
The stock added 1.79 to 25.82 dollars. Macy's shares also got a boost, adding 1.16, or 5.5%, to 22.17 dollars.
Kohl's climbed 4.9% after the department store chain said it will open Amazon shops in 10 of its stores. Kohl's shares gained 1.98 to 42.37 dollars.
The fallout from Hurricane Harvey, which slammed the Gulf Coast of Texas last month, forced Newell Brands to cut its profit forecast, sending its shares lower Wednesday.
The consumer products maker noted that almost all of its resin suppliers with facilities in Texas and Louisiana shut down after that storm hit.
Newell's shares gave up 1.69 dollars, or 3.5%, to 47.03 dollars.
United Continental slid 1.3% after the airline cut its third-quarter outlook, citing increased fuel costs due to Harvey. The stock fell 77 cents to 60.33 dollars.
Several travel booking companies also slid on Wednesday.
Trivago tumbled 16.3% after the company cut its profit and revenue guidance. The stock lost 2.44 to 12.49 dollars.
Rivals Expedia and TripAdvisor also fell.
Expedia shed 3.22 dollars, or 2.2%, to 144.39 dollars, while TripAdvisor gave up 24 cents, or 0.5%, to 44.31 dollars.
The dollar rose to 109.37 yen from 108.66 yen on Tuesday. The euro fell to 1.1913 from 1.1918 dollars.
In other energy trading, wholesale petrol dipped three cents to 1.67 dollars a gallon.
Heating oil rose a penny to 1.76 dollars a gallon. Natural added three cents to three dollars per 1,000 cubic feet.
Among other metals, silver shed three cents to 17.91 dollars an ounce, while copper gained two cents to 3.15 dollars a pound.
Global stock markets were mixed.
In Europe, Germany's Dax gained 0.7%, while France's CAC 40 rose 0.3%.
The FTSE 100 index of leading British shares fell 0.3%.
Earlier in Asia, Japan's Nikkei 225 slipped 0.1% and South Korea's Kospi lost 0.3%.
Hong Kong's Hang Seng index fell 0.5%.