WASHINGTON -- Congressional bargainers formally completed a bipartisan border security pact late Wednesday and President Donald Trump laboured to frame it as a political win, even though it contains only a fraction of the billions for a "great, powerful wall" that he's been demanding for months.

Trump is expected to grudgingly accept the agreement, which was completed just before midnight. The measure -- 1,768 pages of legislation and explanation -- would avert another government shutdown and give the president what Republicans have been describing as a "down payment" on his signature campaign pledge.

Earlier in the day, Trump said he was still waiting to learn what its final language would be before making a decision. But he's not waiting to declare victory, contending at the White House on Wednesday that a wall "is being built as we speak."

Indeed, work on a first barrier extension -- 14 miles in Texas' Rio Grande Valley -- starts this month, approved by Congress about a year ago along with money to renovate and strengthen some existing fencing. But that's a far cry from the vast wall he promised during his campaign would "go up so fast your head will spin."

Sounding like he was again in campaign mode, he told a law enforcement group on Wednesday, "It's going to be a great, powerful wall. ... The wall is very, very on its way."

Carried away by his own enthusiasm, perhaps, he added, "You are going to have to be in extremely good shape to get over this one. They would be able to climb Mount Everest a lot easier, I think."

Trump has a history of balking at deals after signalling he was on board. But barring White House discovery of any objectionable provisions, he was expected to acquiesce, according to White House officials and other Republicans close to the White House who spoke on condition of anonymity because they weren't authorized to discuss the matter publicly.

Trump and his aides have also signalled that he is preparing to use executive action to try to secure additional money for the wall by tapping into existing federal dollars without any congressional sign-off so he can show supporters he's continuing to fight. That could lead to resistance in Congress or federal court.

But assuming there are no surprises in the final text, "I think he's going to sign it," conservative Rep. Mark Meadows, R-N.C., a close ally of the president, said Wednesday. He warned, though, that "it would be political suicide" if Trump signed the deal and then failed to take action to secure additional funding for the wall using his executive powers.

Swallowing the deal would mark a major concession by Trump, who has spent months insisting the situation at the southern border represents a national security crisis that demands an impregnable wall. He also had insisted he would accept nothing less than $5.7 billion for the barrier -- a demand that forced the 35-day partial shutdown that left hundreds of thousands of federal workers without paychecks and Republicans taking the brunt of the blame. There is no appetite for a repeat.

The deal, which lawmakers reached this week, would provide less than $1.4 billion for border barriers while keeping the government funded through the end of September. While some conservatives, Fox News commentator Sean Hannity among them, have balked at the deal, other allies of the president have urged him to sign it and move on.

In private conversations since the deal was first announced, Trump has complained, calling the committee members poor negotiators, said a person familiar with the conversations who was not authorized to speak publicly. He has also made clear that he wanted more money for the wall and has expressed concern the plan is being framed as a defeat for him in the media.

There is also little doubt the deal will pass Congress, barring eleventh-hour surprises, with "no" votes most likely coming from liberal Democrats and conservative Republicans. Democratic leaders are selling it as solid compromise that will keep the government open.

The White House has long been laying the groundwork for Trump to use executive action to bypass Congress and divert money into wall construction. He could declare a national emergency or invoke other executive authority to tap funds including money set aside for military construction, disaster relief and counterdrug efforts.

The legislation would push Immigration and Customs Enforcement to gradual reduce the number of unauthorized immigrants it detains -- currently 49,000 -- though this year's figure would remain higher than last year's.

New barriers could only be built using existing technology, not solid concrete or steel walls that have been proposed and Trump has favoured since his presidential campaign. Barriers would be curbed along certain portions of the border.

The measure also provides money to upgrade monitoring and surveillance equipment at border ports of entry and between them. There would be funds to hire more customs agents and immigration judges, improve conditions for detained immigrants and humanitarian aide to Central American countries to help stem the flood of migrants.

Facing opposition from Trump, Democrats lost their bid to make sure employees of federal contractors receive back pay for wages lost during the last shutdown. Federal workers have been paid for time they were furloughed or worked without paychecks.

Also not making the bill was a simple extension of the Violence Against Women Act. Democrats say this will give them a chance later this year to rewrite the law by including protections for transgender people.

Trump kept his cards close, telling reporters he would be taking "a very serious look" at the final text once the White House receives it and watching for any "land mines."

Lawmakers need to pass some kind of funding bill by midnight Friday to avoid another shutdown.

Meanwhile, active-duty troops from dozens of U.S. military units around the country are flowing to the southern border as part of the latest plan to send 3,750 new forces to help with surveillance and install more wire barriers.

As of this week, the military had installed about 105 miles of wire along the border and planned an additional 140 miles of the concertina wire. The bulk of that will be in California and Arizona, in locations between ports of entry that are identified by U.S. Customs and Border Protection as vulnerable.

------

Associated Press writers Zeke Miller, Jonathan Lemire and Andrew Taylor contributed to this report.