The Dow Jones industrial average fell on Thursday as investors assessed the possibility of the government shutting down at the end of the week.

The 30-stock index closed 97.84 points lower at 26,017.81 after falling 168.33 points at its session lows. The alternated between gains and losses throughout the session before closing 0.2 percent lower at 2,798.03.

Congress needs to pass a spending bill by the end of Friday to avoid a government shutdown. Historically, a government shutdown has led to a short-term pullback in the stock market.

"This is definitely related to the shutdown," said Larry McDonald, head of the U.S. macro strategies at ACG Analytics and creator of The Bear Traps Report. "The chances of a shutdown have increased in the past few weeks, but the market's been ignoring it."

The Dow and S&P 500 posted record closes on Wednesday, shaking off a sharp intraday reversal in the previous session. The Dow closed above 26,000 for the first time, while the S&P 500 finished above 2,800 for the first time.

"Congress trying to avert a government shutdown is a concern," said Anthony Conroy, president at Abel Noser. "People are also taking a bit off the table. We've had record after record after record."