WASHINGTON — Congressional efforts to reach a border security deal ahead of another government shutdown broke down on Sunday over Democratic demands to limit the detention of undocumented immigrants, as President Trump moved more troops to the border and prepared to rally supporters in Texas on Monday.

The 17 House and Senate negotiators had hoped to finalize a border security agreement on Monday, but hours before that deadline, communications had stopped, lawmakers and aides said.

Meantime, the Trump administration was moving on its own to fortify the southwestern border with thousands of active-duty military troops. The number of deployed troops on the Mexican border was set to exceed the high of 5,900 reached around the November elections, as about 3,700 active-duty troops were being sent to assist with the Department of Homeland Security’s border patrol efforts.

Senior officers are voicing greater worries that the deployed troops are not conducting the training needed for their regular missions, while other military units must now pick up the routine duties on behalf of their deployed colleagues.

“The Wall will get built one way or the other!” Mr. Trump wrote on Twitter on Saturday afternoon.

During the last lapse in funding, hundreds of thousands of workers were either furloughed or worked without pay, and it cost the United States economy $11 billion. Another shutdown would hit some agencies at an even worse time. The Internal Revenue Service, for instance, is just entering tax season.

Lawmakers held out the possibility that Mr. Trump could find some face-saving way to fortify border security and build some structures without resorting to a precedent-setting emergency declaration. Mick Mulvaney, the acting White House chief of staff, said the president had asked him to “comb through the law” and “go find money in any place we could” to fully fund a wall.

“There’s pots of money where presidents, all presidents, have access to without a national emergency,” Mr. Mulvaney said on NBC’s “Meet the Press.”

Senior Republican aides said Senator Mitch McConnell, the majority leader, and his leadership team were frustrated with the Democrats because they believed they had persuaded Mr. Trump to agree to a package for border security improvements that consisted mostly of repairs and extensions to existing barriers. Their major concern now, people close to the process said, is that Stephen Miller, the president’s hard-line adviser on immigration, would convince him that accepting a compromise on detention beds would be a humiliation that would cost him with his base.

In what one Defense Department official described as a surreal scramble, Pentagon officials met on Friday and over the weekend to identify which Army Corps of Engineers construction projects would be tapped for money to help build Mr. Trump’s wall if the president declared a national emergency.

Officials scoured the language of multiple draft declarations that Mr. Trump might invoke if a deal is not reached or he rejects what lawmakers agree upon. Mr. Trump’s top national security aides are scheduled to meet on Monday to discuss the matter. Mr. Trump is then to convene a full cabinet meeting on Tuesday, officials said.

If Mr. Trump declares a national emergency to build the wall, Democrats are expected to sue to block construction and halt any shifting of funds. House Democrats are preparing legislation that would limit the president’s ability to unilaterally commandeer wall funding.

Mr. Trump is set to hold a rally in El Paso on Monday night, using the border city as evidence for his exaggerated claim that a wall would reduce crime.

[Read about the message El Paso is sending to Mr. Trump before the rally: Don’t speak for us.]

Prominent Democrats from the area, including Beto O’Rourke, a possible Democratic presidential candidate and former representative for most of the city, and his freshman successor, Representative Veronica Escobar, have denounced Mr. Trump’s claims that El Paso became a safe city only after a physical barrier was built there. Ms. Escobar called the president a liar.