 -- Lawmakers narrowly avoided a partial shutdown of the Department of Homeland Security and furloughing thousands of employees Friday when they reached a last-minute deal to approve a one-week funding measure for the department.

Just two hours before the midnight deadline, the House voted 357 to 60 to fund the department for one week. The Senate passed the measure earlier in the evening by a voice vote.

President Obama signed it into law late Friday.

Less than one hour before the vote, House Minority Leader Nancy Pelosi sent her Democratic colleagues a letter urging them to advance the seven-day measure.

Though the department will be funded, the one-week measure will set up a new round of fighting for lawmakers on Capitol Hill. The dysfunction that has become all too familiar on Capitol Hill was on full display today as the House earlier failed to secure enough votes to pass a short-term funding bill that would have kept the department open for three weeks.

That last-minute strategy proposed by House Republicans failed with a vote of 203 to 224. Fifty-two Republicans opposed the measure while 12 Democrats supported it.

President Obama held a meeting in the Oval Office late Friday with DHS Secretary Jeh Johnson and OMB Director Shaun Donovan to discuss the potential shutdown, White House Press Secretary Josh Earnest said. The president personally phoned House Minority Leader Nancy Pelosi and Senate Minority Leader Harry Reid to receive an update on the situation.

The evening’s drama rounds out months of fighting between Democrats and Republicans over the funding. Republicans have wanted to link any funding for the department to immigration. Earlier this month, the House passed a bill that would fund the department through the end of the fiscal year while also blocking President Obama’s recent executive actions on immigration.

But Democrats opposed that plan, instead pushing for a clean funding bill. Earlier in the day, the Senate passed a clean funding measure with a vote of 68 to 31 to fund the Department of Homeland Security through Sept. 30.

“We passed a full-year funding for the Department of Homeland Security,” Sen. Barbara Mikulski, D-Md., said. “It means we did our job so that those men and women working in every agency can do their job to protect America. The Senate has done its job. Now, the House has to do its job.”

Lawmakers will now have one week to hammer out their differences on the funding and immigration. If not, the Department of Homeland Security will have to furlough approximately 40,000 workers. But 80 percent of its 240,000-person workforce would be required to work without pay. This figure includes 40,000 Customs and Border Protection officers, 5,000 Transportation Security Administration security screeners, and 13,000 Immigration and Customs Enforcement agents.

ABC News' John Parkinson contributed to this report.