SOMETIMES, POLITICIANS can surprise you, even in Washington. After months of hard bargaining, a bipartisan group of eight senators has produced a sweeping proposal to overhaul the nation’s immigration system. The legislation would revamp almost every major program affecting immigration, extending legal status to most of the 11 million illegal immigrants in the country, dramatically expanding legal immigration for at least the next decade and awarding more visas based on education and merit at the expense of relatives of U.S. citizens.

The legislation is a milestone of pragmatism that, through tough trade-offs, would bring common sense to a broken immigration system that has come to symbolize dysfunction in Washington. Despite its sensible and necessary reforms, the bill faces stiff headwinds, especially in the House.

The measure is massive, and intentionally so. The bill’s authors seemed determined to fix so many problems and satisfy so many constituencies that it would be propelled from the outset by groups representing business, labor, agriculture, high tech, Hispanics and immigrants.

Critically, the bill would provide legal status for most of the undocumented immigrants already in America, as long as they pass a background check, have a clean record and pay a fine. People who have been living in fear could work and travel without risk of deportation — though they would remain ineligible for most federal benefits for the time being. If an array of other benchmarks are satisfied, most could apply for permanent-resident green cards (after 10 years) and citizenship (after 13).

The legislation would require employers to check the immigration status of most new hires and, at Republicans’ insistence, would pour billions of dollars into security along the Southwest border, with a requirement to thwart at least 90 percent of illegal crossers in the most heavily trafficked sectors. That’s fine in theory. In practice, the risk is that immigration hawks will insist on unattainable, or unverifiable, benchmarks of security as a pretext to impede progress toward citizenship for illegal immigrants. The frontier already is dramatically less porous than it was five years ago.

Still, immigration advocates have plenty to cheer in the legislation, including steps to extend hundreds of thousands of visas annually to low-skilled and agricultural workers; to nearly double the number of visas offered to foreign engineers and scientists, whose services are prized by high-tech firms; and to clear the backlog of several million relatives of U.S. citizens who have been waiting years to immigrate. So-called DREAMers — undocumented immigrants brought to America as children — would get legal status and be eligible to apply for green cards in just five years.

Trade-offs include eliminating the visa lottery program, which provides 55,000 visas annually, mainly for Africans and Eastern Europeans, and visa preferences for some relatives of U.S. citizens, such as adult siblings.

The concerns of some Democrats about an influx of foreign labor and the potentially depressive effect on wages seem to have been addressed by deals between the U.S. Chamber of Commerce and the AFL-CIO and between agribusiness and farm workers. The main question now is whether conservative Republicans, who have choked on the idea of “amnesty” for so long, can get behind any legislation that includes a path to citizenship for illegal immigrants.

That’s why GOP senators — especially Marco Rubio of Florida, a member of the Gang of Eight — will have such an important role to play. After seeming to waver, he appears to be all in for the legislation he helped broker. Whether he can sell it to his party’s backbenchers may make the difference in determining whether America, at last, can fashion a workable immigration system.