A man holds a U.S. flag while receiving his proof of U.S. citizenship during a ceremony in San Francisco, California January 30, 2013. President Barack
A man holds a U.S. flag while receiving his proof of U.S. citizenship during a ceremony in San Francisco, California January 30, 2013. President Barack Obama said on Wednesday that he believes it is possible to get an overhaul of the U.S. immigration system certainly by the end of the year if not the first half of 2013. REUTERS/Robert Galbraith (UNITED STATES - Tags: POLITICS SOCIETY IMMIGRATION) (ROBERT GALBRAITH)

WASHINGTON (Reuters) - The Senate on Friday plunged into a spirited debate on overhauling the country's immigration rules, with a verdict likely by the end of June on legislation that could define President Barack Obama's final years in office.

The "Border Security, Economic Opportunity and Immigration Modernization Act," a nearly 900-page reworking of the nation's 27-year-old immigration law, faces a tough fight in the Democratic-held Senate and an even harder battle in the more conservative House of Representatives later this year.

At its core is a plan to move 11 million people residing in the United States illegally - many of whom came from Mexico years ago - out of their illegal status and onto a 13-year path to citizenship.

At the same time, the legislation would spend around $6 billion more to strengthen border security and would change the way temporary visas are issued, putting more emphasis on helping U.S. farmers and high-tech industries get foreign labor.

"It is gratifying to see the momentum behind this package of common-sense reforms, which will make our country safer and help 11 million undocumented immigrants get right with the law," Senate Majority Leader Harry Reid said.

While he promised to give senators ample opportunity to change the bill - a few dozen amendments are expected - Reid also warned that he would not allow opponents to debate the measure endlessly. Work on the bill will be wrapped up before the July 4 recess, Reid, a Nevada Democrat, said.

The bill's handling of the 11 million undocumented residents is particularly problematic for many Senate Republicans who see it as rewarding people who broke the law by entering the United States illegally while others waited in foreign lands for their applications to be processed.

"We can't reject a dutiful, good person to America and then turn around and allow someone else who came in illegally to benefit from breaking our laws to the disadvantage of the good person," said Republican Senator Jeff Sessions of Alabama.

Sessions, who has been a leading voice against the legislation, added: "It will definitely give amnesty today" to the 11 million.

Sessions and other senators are expected to push for greater border security efforts and are also likely to try to eliminate the pathway to citizenship for the 11 million.

Nevertheless, backers of the bill were confident that it will pass within a few weeks, putting the onus on the Republican-controlled House to tackle the immigration overhaul, a top issue to Hispanic voters who mainly backed Obama in last year's election.

Republican Senator John McCain, a member of the "Gang of Eight" that wrote the legislation, said he remains optimistic that there are at least 60 votes in the 100-member chamber to pass the bill, the number needed to clear any procedural roadblock.

"We've got over 60 votes. I'm confident of that," McCain told Reuters.

He said he believed that by the time the amendment process ends, backers will have 70 votes on passage, the number supporters are aiming for to put pressure on the House to act.

"There are some real concerns about border security that we have to work through, but I'm confident that we will be able to do so," McCain said.

But Republican Senator Mike Lee cited the emerging scandal involving the U.S. spy agency's domestic surveillance efforts to oppose the immigration bill, which he said would authorize another excessive federal effort.

"Did the American people have any idea that the (2001) PATRIOT Act would empower the National Security Agency to spy on all Americans through their cell phones and computers?," Lee, of Utah, asked.

"What makes any of us - least of all any conservative - believe this immigration bill is going to work out any better?" Lee added, calling for an incremental rather than comprehensive approach to immigration reform.

The legislation represents a big test for the highly polarized and unpopular Congress, which has been unable to handle even basic chores, like agreeing to a federal budget.

It may be an even bigger test for Obama, who earlier this year failed to get the Senate to approve another major legislative objective, a crackdown on gun violence.