WASHINGTON — President Trump called on Tuesday for shutting down the federal government if Congress does not crack down on illegal immigration, even as congressional negotiators closed in on a major budget deal that would set spending levels for two years and break the cycle of fiscal crises that has bedeviled the nation’s capital.

On Tuesday night, the House approved a stopgap spending bill that would increase military spending through September while keeping funds flowing to the rest of the government for six weeks. The House measure is unlikely to pass the Senate, where Democrats insist that an increase in military funds be matched with additional domestic spending.

But the House vote was a first step in what congressional leaders hoped would be a legislative dance that yields a bipartisan spending deal. Mr. Trump’s comments, though combative, had little to do with the delicate negotiations, a fact that appeared to elude Mr. Trump. They did, however, add a note of uncertainty.

“I’d love to see a shutdown if we don’t get this stuff taken care of,” Mr. Trump said at a meeting with lawmakers and law enforcement officials to discuss gang violence. “If we have to shut it down because the Democrats don’t want safety,” he added, “then shut it down.”