President Donald Trump said he has signed a spending bill funding the federal government for the next six months, reversing a veto threat he made earlier Friday that shocked Washington after his administration had previously said he would approve the legislation.

Trump’s turnabout came after a meeting with Defense Secretary James Mattis, who advocated for the bill’s increases in defense spending and wanted the relative certainty of six months of assured funding.

“My highest duty is to keep America safe. Nothing more important,” Trump said at the White House. “But I say to Congress: I will never sign another bill like this again.”

The spending bill appeared to only be waiting for Trump’s signature when he tweeted Friday morning that he was “considering a VETO” because the bill does not fully fund a wall on the Mexican border or create a solution for the Deferred Action for Childhood Arrivals program, a program protecting some undocumented immigrants from deportation that Trump chose last year to end.

The veto threat injected chaos into what appeared to be the end of a protracted struggle to settle on a funding plan for the federal government. A month of negotiations between Republicans and Democrats culminated in a deal to raise defense and domestic spending following a bruising fight that triggered a shutdown in January.

Trump called it a “ridiculous situation” before handing over his podium to Commerce Secretary Wilbur Ross to briefly discuss a trade deal with South Korea. Afterward, Trump said he wants the power to issue line-item vetoes on spending bills -- a power many presidents have demanded, and that Congress has never granted -- and that the Senate should eliminate the ability of a minority to filibuster legislation.

The federal fiscal year began Oct. 1.

Top administration officials including Vice President Mike Pence and Office of Management and Budget Director Mick Mulvaney gave assurances on Thursday that Trump would sign the bill, which cleared both chambers of Congress that day.

Trump said he had seriously considered vetoing the bill but “because of the incredible gains we’ve been able to make for the military that overrode any of our thinking.”

Shortly after Trump’s tweet threatening a veto, Republican House Speaker Paul Ryan spoke to Trump and encouraged him to sign the bill, according to a person familiar with the conversation. Ryan stressed that the funding bill included many victories for the president, especially on military spending.

A veto would have almost certainly triggered a partial government shutdown, the third since the start of the year, since many lawmakers left Washington after the legislation won final passage. Funding for the federal government was set to run out at 12:01 a.m Saturday.

“We wanted to include DACA in this bill, but Democrats wouldn’t do that,” Trump said.

Congressional aides said that the White House had suggested a three-year extension of the DACA program in exchange for US$25 billion in funding for the border wall, a proposal Democrats rejected. Democrats offered to provide the money but only if Trump agreed to provide DACA recipients with a path to U.S. citizenship, as he had in an earlier debate. The White House rejected the counteroffer.