WASHINGTON (AP) — The bipartisan coalition behind a contentious overhaul of immigration laws stuck together on a critical early series of test votes Thursday, turning back challenges from conservative critics as the Senate Judiciary Committee refined legislation to secure the borders and grant eventual citizenship to millions living in the United States illegally.

In a cavernous room packed with lobbyists and immigration activists, the panel rejected numerous moves to impose tougher conditions on border security before immigrants who entered the country illegally could take the first steps along a new pathway toward citizenship.

Republicans Lindsey Graham of South Carolina and Jeff Flake of Arizona — part of a bipartisan group that helped draft the measure — joined all 10 Democrats in blocking the changes. Sen. Orrin Hatch, a Utah Republican who has yet to announce a position on the overall legislation, opposed one and supported the others.

Assuming the core political alignment remains intact, the committee is expected to approve the measure within two weeks and clear the way for an epic showdown on the Senate floor in June.

White House aides watched from the sidelines as the committee began its work on a bill that President Barack Obama has made a top priority in the opening months of his second term.

Painstakingly negotiated by a bipartisan “Gang of Eight,” the measure would clear the way for tens of thousands of new high-tech and lesser-skilled workers to enter the country while also requiring all employers to check the legal status of their employees. But it was the core trade-off — securing the border against future illegal immigration while setting up a 13-year process by which immigrants unlawfully in the country could qualify for citizenship — that generated the most controversy by far.

Sen. Charles Schumer, a New York Democrat who helped draft the bill, said it would “change our policy so that the people who are needed to help our economy grow can come into this country, and at the same time we will note that when families are divided the humane thing to do is bring those families back together.

“Because we so dramatically stop the flow of illegal immigration, we can do both. And we do, and do it fairly.”

Republican critics made no claim they can defeat the bill in committee and concentrated instead on casting doubt on assertions that it will secure the U.S.-Mexican border before it allows immigrants illegally in the United States to take their first steps toward legal status.

“The triggers in the bill that kick off legalization are weak,” said Sen. Charles Grassley of Iowa, referring to a series of requirements that must be met before unauthorized immigrants can apply for legal status. “No one can dispute that this bill is legalization first, enforcement later.”

He said the last extensive overhaul of immigration in 1986 had also claimed it would end illegal immigration. “We thought we were so certain...and we screwed up,” he said of those who voted for the bill 37 years ago, himself among them.

Sen. Jeff Sessions, R-Ala., said he feared the result of the measure would be a shell game in which “amnesty takes effect but not enforcement.”

The political stakes were high. One Republican who helped draft the legislation and another who seems destined to oppose it have ties to the tea party and are both considered possible presidential candidates in 2016. And despite the deep partisan differences, an atmosphere of cordiality reigned, marred only once when tempers flared briefly in a clash between Schumer and Texas Republicans John Cornyn and Ted Cruz.

The first challenge to the legislation came on Grassley’s proposal to require six months to elapse between the time the southern border is secured and immigrants may begin seeking legal status, a step that Schumer said would “delay, probably forever, any legalization” for immigrants now living in the country without authorization.

The second was advanced by Sen. Mike Lee, R-Utah, and sought to require that both houses of Congress vote to declare the border secure before the citizenship process could begin. Under the legislation as drafted, the secretary of Homeland Security has the authority to make that declaration.

“Many of us are concerned that the border fencing and security triggers in this bill leave too much discretion to the secretary,” Lee said.

Graham said he feared the result would inevitably be deadlock, in which the Democratic-controlled Senate would declare the border secure while the Republican-controlled House would counter that it was not.

Cruz later tried to require that the number of U.S. border patrol agents be tripled on the U.S.-Mexico border and the amount of equipment stationed there be quadrupled before any immigrant could apply for a change in legal status.

Also rejected was Sessions’ call for construction of 700 miles of double-fencing along the Mexican border. Hatch opposed Cruz’ proposal and supported the other changes that were rejected. He has not yet declared a position on the legislation, although he is expected to be heavily influenced by the number of visas it approves for workers in the high-tech industry, which has a significant presence in Utah.

Eager to demonstrate their openness to changes, Democrats stressed that they had agreed to a number of Republican proposals.

One, advanced by Grassley, specifies that a requirement for 90 percent of would-be border crossers to be stopped or turned back must apply to the entire southern border, not just “high-risk” sectors.

But a verdict on perhaps the most contentious proposal — to assure that immigrants in the country illegally are treated the same regardless of sexual orientation — is not expected to come to a vote until next week or the week after. Gay rights groups are adamantly seeking the provision be inserted into the measure, but Republicans have warned that could splinter the coalition behind the bill and doom its chances for passage.

The legislation was drafted by Democratic Sens. Schumer and Dick Durbin of Illinois, who are on the committee, and Bob Menendez of New Jersey and Michael Bennet of Colorado, who are not, as well as Flake and Graham and Republican Sens. Marco Rubio of Florida and John McCain of Arizona.

Under the legislation as drafted, immigrants who entered the United States illegally before Dec. 31, 2011, and have been in the country since then may apply for Registered Provisional Immigrant status. To qualify, they must pass a background check, have no serious criminal conviction on their record, pay any back taxes they owe and a pair of $500 fines.

At the end of a decade, they may apply for permanent residency, pay an additional fine of $1,000 and meet other requirements. After an additional three years, they may apply for naturalization.