Just hours after threatening a veto, President Trump said Friday afternoon that he had signed a “ridiculous” $1.3 trillion spending bill passed by Congress early Friday and averted a government shutdown.

In a morning tweet, Trump said he might veto the omnibus bill because it does nothing to address the fate of young undocumented immigrants known as “dreamers” and does not fully fund his border wall.

But speaking to reporters at the White House about four hours later, Trump said he had decided to sign the bill despite his reservations, arguing that it provides much-needed funding for the military, including a pay increase for troops and new equipment.

“My highest duty is to keep America safe,” Trump said. “We need to take care of our military.”

Still, he voiced disdain for the way the hasty way the bill was passed.

“I say to Congress, I will never sign another bill like this again,” Trump said, also calling on Congress to give him a line-item veto, a tool that the U.S. Supreme Court has said is unconstitutional for the president.

“There are a lot of things that I’m unhappy about in this bill,” he said later in his meandering 20-minute remarks, telling reporters that he had “very seriously” considered a veto.

The announcement, which Trump teased in a separate tweet an hour before it began, capped off a wild morning in the White House and on Capitol Hill. Several aides scrambled to convince the president not to follow through with his threat.

In his Friday morning tweet, Trump said that those protected from deportation by the Obama-era Deferred Action for Childhood Arrivals (DACA) program have been “totally abandoned” by Congress, and he blamed the Democrats.

Trump, who decided last fall to end the DACA program, was seeking a deal that would give Democrats protections they sought for the program’s recipients in exchange for additional funding of $25 billion for his long-promised U.S.-Mexico border wall. The bill includes a minor down payment of $1.6 billion on his marquee campaign promise.

“I am considering a VETO of the Omnibus Spending Bill based on the fact that the 800,000 plus DACA recipients have been totally abandoned by the Democrats (not even mentioned in Bill) and the BORDER WALL, which is desperately needed for our National Defense, is not fully funded,” Trump said in his tweet.

In his remarks, at the White House, Trump said he was disappointed in the level of border-wall funding but pledged to do as much as possible with it and to seek more money from Congress.

Saying he was addressing Hispanics, Trump argued his party was more interested in the fate of “dreamers” than Democrats.

“Republicans are much more on your side than the Democrats, who are using you for your own purposes,” the president said. His aides have argued Democrats are trying to use DACA as an election issue.

People familiar with Trump’s thinking said the president was frustrated with the bill and the coverage it was receiving, particularly on Fox News, where critics took aim at the level of spending in the bill.

“He doesn’t care as much about the spending levels, but he knows all of his conservative friends do,” said a senior White House official, who requested anonymity to speak more candidly.

Lawmakers have left town on a two-week recess, some of them on overseas trips and with no plans to return to Washington. The House passed the bill midday Thursday, and the Senate cleared the measure shortly after midnight.

Trump had until midnight Friday to sign a bill or a government shutdown would ensue.

The legislation funds the federal government for the remainder of the 2018 budget year, through Sept. 30, directing $700 billion toward the military and $591 billion to domestic agencies. The military spending is a $66 billion increase over the 2017 level, and the non-defense spending is $52 billion more than last year.

The spending bill is widely expected to be the last major legislation that Congress will pass before the November midterm elections, which had increased pressure to jam the bill full of odds and ends, with provisions addressing everything from gun safety to invasive carp.

The lack of an immigration deal in the spending bill had set already set off a round of recriminations, with the White House aggressively trying to deflect responsibility for the failure.

Trump’s veto threat only intensified the blame game on Friday morning.

“Let’s not forget that you ended DACA and torpedoed every possible bipartisan fix. This is on you,” Rep. Tim Ryan (D-Ohio) said on Twitter.

Rep. Mark Pocan (D-Wis.) accused Trump of making a “loser’s bluff.”

“Go ahead and veto the omnibus over DACA. We dare you,” Pocan said on Twitter. “Everyone knows you’re the reason DACA recipients are abandoned.”

Meanwhile, lawmakers who opposed the spending bill on other grounds used the occasion to urge Trump to follow through with his threat.

Rep. Mark Meadows (R-N.C.), head of the hard-right Freedom Caucus, urged Trump to veto the bill. “[email protected] would fully support you in this move, Mr. President. Let’s pass a short term [continuing resolution] while you negotiate a better deal for the forgotten men and women of America.”

Also urging Trump to veto the bill was Sen. Bob Corker (R-Tenn.), who in a tweet Friday morning said: “Please do, Mr. President. I am just down the street and will bring you a pen. The spending levels without any offsets are grotesque, throwing all of our children under the bus. Totally irresponsible.”

Before the Senate’s early-morning vote Friday, Corker had complained about the process of rushing the bill through Congress.

Several other conservative lawmakers egged Trump on Friday morning, complaining about the amount of spending and the rushed process. But there is no indication that Trump shares those concerns.

Instead, in his veto threat Friday, Trump proposed something that conservative hard-liners have largely rejected in recent months — trading dreamer protections for border wall money. Conservatives, emboldened by a White House proposal released in January, have insisted that any immigration deal go farther, cutting several programs that allow foreign nationals to live in the U.S. legally.

Other senior Republicans began making their own Twitter pleas urging Trump to sign the bill. Senate Majority Whip John Cornyn, rattled off several policy wins in a Friday tweet directed at the president, including a gun-related measure long championed by the Texas Republican that was included in the 2,232-page spending measure.

“While (Democrats) obstructed normal appropriations process, forcing an Omnibus, the benefits of Omnibus to national security, border security, opioid crisis, infrastructure, school safety and fixing gun background check system are important and will save lives. @realDonaldTrump,” Cornyn tweeted Friday.

“Art of the deal wrecker,” was how Sen. Tim Kaine (D-Va.) sized up the president’s veto threat Friday morning. He urged the president to sign the bill.

“One day after his own (Office of Management and Budget) director said he would sign it, that he’s now saying he’s thinking about vetoing it,” Kaine told reporters. “What, does he just want to create more confusion and chaos? I don’t get it.”

Kaine said Trump’s professed concern about DACA recipients is not sincere because he walked away from an offer from Democrats weeks ago to protect them in exchange for more border security funding.

“He was the one who poured cold water on it and killed it among the Republicans just a month ago,” Kaine said.

“I hope he doesn’t do it. That’s my reaction,” said Sen. Johnny Isakson (R-Ga.), of Trump’s threat.

“I don’t think what we did was the best thing we could have done,” he added. “But it was the only thing we could have done. So to veto it wouldn’t make a lot of sense to me.”

“This is classic Trump,” said Sen. Chris Van Hollen (D-Md.). “He says one thing and then he does something completely different.”

Van Hollen added, “He’s actually one of the worst negotiators I’ve ever seen.”

Although Trump aides declared Thursday that Trump intended to sign the bill, there were signs of his displeasure with various aspects of it.

On Wednesday, House Speaker Paul D. Ryan (R-Wis.) rushed to the White House to reassure Trump.

The president was upset with the amount of money for his border wall, and he griped about a proposed tunnel between New York and New Jersey — a project beloved by Senate Minority Leader Charles E. Schumer (D-N.Y.) — that Trump has ferociously tried to block as part of the negotiations.

Veto threats were made then, too, but after conversations with Ryan and Senate Majority Leader Mitch McConnell (R-Ky.), the White House issued a statement saying Trump supported the bill.

“Is the president going to sign the bill? The answer is yes.” Mick Mulvaney, director of the Office of Management and Budget, told reporters at the White House on Thursday afternoon.

On Thursday, the White House also issued a lengthy release titled, “The American People Win as President Donald J. Trump’s Priorities are Funded,” with a long list of specific items in the massive legislation.

Asked about the president’s tweet on Friday, White House spokesman Hogan Gidley said in a statement: “The tweet stands for itself.”

Josh Dawsey, Erica Werner, Sean Sullivan and Seung Min Kim contributed to this report.