Stocks on Wall Street vacillated between gains and losses as a government shutdown loomed and a Federal Reserve official suggested the bank is more flexible about its plans for monetary policy than it had indicated earlier in the week.

Speaking on CNBC, the president of the Federal Reserve Bank of New York, John Williams, said the central bank could reassess its views next year. The S&P 500 stock index, which was slightly higher in early trading, began to climb as Mr. Williams spoke.

But many of those gains faded soon after he was done.

The stock market’s most recent swoon began on Wednesday afternoon, after the Fed, citing the strength of the economy, signaled that it planned to keep raising interest rates and shrinking the extraordinary amount of support it has provided to financial markets in the decade since the financial crisis.

With stock benchmarks down sharply in the past few months, and concerns about economic growth mounting, investors had hoped that the Fed would say it had taken note of their concerns.