(Reuters) - Hours before funding expires for the Department of Homeland Security, the U.S. Senate on Friday approved nearly $40 billion to keep the agency operating through September and avoid a midnight shutdown.

The House of Representatives is expected to ignore the legislation because it does nothing to stop President Barack Obama's executive order, issued in November, that removed the threat of deportation for 4.7 million undocumented residents.

Instead, the House on Friday is attempting to pass a three-week extension of current funds for DHS, giving Republicans more time to pursue their fight to reverse Obama's immigration action, which has been temporarily put on hold by a federal judge.

The Senate voted 68-31 for the full-year extension that Democrats have been insisting upon.

DHS funding is the first fiscal measure to test the new, Republican-controlled Congress that was sworn in at the beginning of the year.

Even though Republicans comfortably control the House and have a narrow advantage over Democrats in the Senate, intra-party disagreements have made for a chaotic two months, with the prospect of a partial government shutdown looming over Washington.

The uncertainty and rancor in Congress will continue well into March if the three-week DHS funding bill is enacted later on Friday, as expected.

During Senate debate of the full-year funding bill, Senator Barbara Mikulski of Maryland, the senior Democrat on the appropriations committee said: "You want to protect America? Vote for the clean funding bill. You want to protect America's border, fight for the clean funding bill? You want to make sure we don't have illegal aliens in this country? Make sure we're funding the border control."

She noted that allowing funds to expire would suspend grants that support local first responders in disaster areas, such as snow-bound places where volunteer fire departments are evacuating people on snowmobiles this winter.

(Reporting by Richard Cowan and David Lawder: Editing by Susan Heavey)