President Donald Trump gestures during the Hispanic Heritage Month Celebration in the East Room of the White House on September 17, 2018 in Washington, DC. President Trump hosted the event to celebrate the heritage month with Hispanic leaders.

President Donald Trump on Friday signed a spending bill that will avert a government shutdown despite previously calling the measure "ridiculous" because it did not include funding for a wall along the southern border.

There had been some doubts about whether the president would sign the bill, raising the specter that funding for the government would lapse as early as Monday. But Trump tamped down on concerns from top Republicans in recent weeks, pledging that he would "keep the government open."

In a statement announcing that he signed the bill, the president said he "secured additional funding for border security" and claimed $1.6 billion would go toward building the border barrier. Trump also again made the unsubstantiated claim that Democrats "want drugs and crime to pour into our country."

"America is being respected again — and our people are being protected again. I am pleased to have signed this bill into law," Trump said.

Trump had blasted the spending package, which will fund the departments of Defense, Labor and Health and Human Services for a year, because it did not include the money he wanted for his proposed border wall. The White House has asked for up to $25 billion in funding.

In July, the president brushed off the prospect of a shutdown.

"If we don't get border security after many, many years of talk within the United States, I would have no problem doing a shutdown," Trump said at a news conference at the time.

The president appeared to double down on his pledge to obtain border wall spending as recently as late September.

"I want to know, where is the money for Border Security and the WALL in this ridiculous Spending Bill, and where will it come from after the Midterms," Trump wrote in a Sept. 20 post on Twitter.

Trump tweet

The insistence earned pushback from Republican congressional leaders who worried a shutdown could hurt the party with just over a month left to go before November's hotly contested midterm elections, when the GOP will face down challenges to its control of both the House of Representatives and the Senate.

"I'm confident he will sign it," House Speaker Paul Ryan, R-Wis., said Wednesday. "This funds our military, this funds opioids, this does a lot of the things that we all want to accomplish together, and we've had very good conversations with the president."

On Thursday, White House budget director Mick Mulvaney also weighed in, telling CNBC that the president would table border wall funding until after the midterms.

"We've decided to have that discussion after the election," Mulvaney said on "Squawk Box."

— CNBC's Eamon Javers and Matthew Belvedere contributed to this report.