WASHINGTON (CBSNewYork/AP) — The U.S. House of Representatives late Friday passed a bill extending funding for the Department of Homeland Security by one week — just two hours before a midnight deadline.

The House, by a vote of 357-60, passed the plan that been approved by the Senate earlier in the evening.

READ MORE: Dr. Howard Zucker Stepping Down As New York State Health Commissioner

Earlier, the House had rejected a three-week extension of DHS funding, throwing negotiations into disarray just hours before large portions of the department would have been forced to shut down.

The earlier bill was defeated 203 to 224, with 52 Republicans defecting from the plan despite their leaders’ support for it, and only a dozen Democrats voting in favor of it, CBS News reported.

Some lawmakers were furious.

“You have made a mess,” House Democratic Leader Nancy Pelosi (D-Calif.) said at one point to Republicans, as recriminations filled the House chamber and a midnight deadline neared for a partial agency shutdown.

Even some Republicans readily agreed – including Rep. Peter King (R-N.Y.)

“There are terrorist attacks all over world and we’re talking about closing down Homeland Security. This is like living in world of crazy people,” tweeted Rep. Peter King of New York, a former chairman of the Homeland Security Committee.

In New York, Mayor Bill de Blasio also lambasted the earlier House vote.

“The failure of the House to act to avoid a partial shutdown of the Department of Homeland Security is deeply troubling. This is not the time to jeopardize the security of our nation through political gamesmanship,” de Blasio said in the statement. “With the variety of threats to our national security, the need for adequate funding could not be more paramount to our public safety than now. Keeping our citizens safe is the number one job of government and I urge all our lawmakers to do the job that they were elected to do and fully finance the Department of Homeland Security.”

NYPD Commissioner Bill Bratton also criticized the handling of the Homeland Security funding bill, saying holding the department hostage to politics is irresponsible at best, dangerous at worst.

“If the leadership of the United States — its elected officials — can’t get their act together – an example of how that can impact the security of the United States,” Bratton said.

After the earlier House vote, President Barack Obama met in the Oval Office on Friday evening with Homeland Security Secretary Jeh Johnson and other senior members of his administration to discuss the impending funding deadline and the administration’s response to a potential DHS shutdown, CBS News reported.

He also spoke with Democratic congressional leaders by phone to receive an update on negotiations on Capitol Hill.

READ MORE: Judge Lifts Temporary Pause On Vaccine Mandate For NYC Teachers, Who Now Must Be Vaccinated By Monday

The House until Friday night had been unable to pass any bill that extends funding for DHS past the midnight deadline but doesn’t restrict the president’s actions on immigration. Lawmakers have been sharply divided, CBS2’s Sonia Rincon reported.

“You all need to stop playing games with the safety of the American people,” said U.S. Rep. Corinne Brown (D-Fla.)

But Rep. Louie Gohmert (R-Texas) argued that Obama overstepped his bounds on immigration and his action must be dealt with.

“This president didn’t even have the gumption to write an executive order and sign it,” Gohmert said. “He spoke his new amnesty law into being.”

House GOP leaders had been rallying their caucus to support the three-week plan to give them additional leverage in negotiations with the Senate, arguing to conservatives that the president’s actions would not be implemented over the next three weeks, and that the additional time could give them more time to make hay of the issue, CBS News reported.

Rep. King (R-N.Y.) had warned earlier that Homeland Security funding must not be toyed with.

“The threat from terrorism is greater than at any time since 9/11,” King said. “ISIS is killing people through the world; burning people, beheading people. Al-Shabaab is threatening to blow up malls in the United States. The worst thing we can do is let our enemies think we are backing off, that we are cutting off funding.”

King said earlier this week that it was just plain wrong that members of his own party were holding security funds hostage in a stalemate with President Barack Obama over immigration.

Failure to extend funding to the department would also have a major impact specifically on the Tri-State Area, Rincon reported.

Law and Police Science Professor Maki Haberfeld at John Jay College said the NYPD needs continuity when it comes to its delicate counter-terrorism operations.

“They’re critical — not just right now, they’re super critical right now, given the fact that major terrorist organizations around the world call for attacks on malls; attacks on soft targets,” she said.

And it’s not just the NYPD. Agencies that protect the airports and cities’ transit systems – also potential terror targets — rely on funding from Homeland Security.

“It’s not like, withdraw the funding today and somehow reinstate the money a couple of days later or a few weeks later, and there is no damage to the infrastructure; to the intelligence infrastructure,” Haberfeld said. “It’s critical that we don’t have these lapses. Once we have these lapses, sometimes it’s almost impossible to recover from the damage.”

MORE NEWS: NYPD: Search Continues For Man Seen On Video Slashing Bronx Restaurant Worker

The concerns will all come up again in one week, as House Republicans remain bitterly divided.