WASHINGTON
— In a move that stunned official Washington, Senate Democrats and Republicans reached a compromise Thursday on an immigration bill that had looked certain to fail.

With hundreds of thousands of immigrants and their supporters poised for street demonstrations Monday in many US cities, the pressure was on both sides to find a path to citizenship for at least some of the 12 million living here illegally.

"They looked into the abyss and saw this whole thing falling apart and realized they needed to get something done over a serious issue," says Marshall Wittmann, an analyst with the Democratic Leadership Council. "It was a rare moment of government at its best, and it's not clear how long it will last."

For nearly two weeks, Democrats had blocked all but three votes on amendments to a bipartisan bill that had emerged from the Senate Judiciary Committee. Democrats said they wanted a straight vote on the Judiciary bill, before heading into a tough conference over a House immigration-control bill focused on enforcement and border security. The House bill does not include a path to legalization or citizenship.

The new plan, offered by Senate majority leader Bill Frist late Wednesday, offers a path to legalization for some but not all those currently in the US illegally.

While final details were not available, in general, the compromise would require illegal immigrants who have been in the United States between two years and five years to return to their home countries briefly, then re-enter as temporary workers. They could then begin a process of seeking citizenship.

Illegal immigrants who've been here longer than five years would not be required to return home. Those in the country less than two years would be required to leave without assurances of returning, and take their place in line with others seeking entry papers.

Not everyone was satisfied. A spokesman for Sen. John Cornyn said the Texas Republican was opposed to the plan. There was no immediate reaction from GOP Sens. Jon Kyl of Arizona or Jeff Sessions of Alabama, two other prominent critics of earlier proposals dealing with illegal immigrants.

Other thorny issues remain to be clarified. Senate leaders had yet to unveil draft legislation to make sure that only legal workers are hired in the future, for one.

Though President Bush was expected to give his nod to the Senate compromise later Thursday, reaction from the House of Representatives was less predictable.

Even so, a celebratory news conference by Senate leaders Thursday underlined the expectation that senators could pass the most sweeping immigration bill in two decades, and act before leaving for a two-week vacation at the end of the week.

"We have a great opportunity to deliver to the American people what they expect, what they deserve" - a bill that includes both enforcement and a program to deal with those already in the country illegally, said Senator Frist.

As outlined, the measure would provide for enhanced border security, regulate the future flow of immigrants into the US, and offer legal status to millions of men, women, and children here unlawfully.