The US Senate on Thursday adopted sweeping reforms of immigration law that would allow millions of undocumented workers to seek legal status in the US.
The bill passed 62-36 despite deep divisions within the majority Republican Party and among Americans.
The Senate bill has the bipartisan support of Republican Senator John McCain and Democratic Senator Edward Kennedy as well as the backing of President George W. Bush.
Bush saluted passage of the text and said effective immigration reform must address both economic and border security needs and "honor America's great tradition of the melting pot."
"I look forward to working together with both the House of Representatives and the Senate to produce a bill for me to sign into law," he said.
However, the bill's final adoption is hardly guaranteed, as it differs sharply from a tougher bill passed in the lower House of Representatives, and the two must be reconciled.
"Today is not the day to celebrate. We have won a big battle but not the war," Senate Democratic leader Harry Reid said.
The Senate bill would create 200,000 temporary work visas for foreigners who take low-skill jobs, and double the number of US Border Patrol agents on the border with Mexico.
Most controversial is a provision that would allow many of the estimated 11.5 million foreign workers here illegally, many of them Mexican, to gain legal status.
The bill also includes funding to build a 600km wall along the Mexican border to block illegal entry.
The consequences of reform are so great for both countries that Mexican President Vicente Fox was on a three-day visit to the US to discuss immigration and labor with US business and political leaders.
"This is a historic day, one to celebrate," Fox told Mexican broadcasters from his presidential jet, in response to the Senate vote.
"It is a wonderful day for the United States and Mexico, but especially for Mexicans in the United States and their families," he said.
Senators wrapped up two months of debate on the reforms Bush has sought for more than two years.
The bill aims to stem illegal immigration but will welcome illegal immigrants who have already been integrated into US society -- derided by some as an "amnesty."
Senators will have difficulty bringing their bill into line with a much tougher version passed by the House in December. The House would make unapproved US entry a federal crime and bolster border security.
Immigrants' rights activists and religious officials fiercely oppose it.