WASHINGTON — Senators writing a landmark immigration bill broke a logjam between farmworker unions and growers Thursday, reaching a tentative agreement on the number of future agricultural visas and pay scales for foreign farmworkers.

Labor unions and agricultural industry leaders had been stuck for three weeks on how to legally bring foreign labor into the United States to pick crops and tend livestock at competitive wages. The issue, which is important to farming states, became a major stumbling block in bipartisan efforts to craft a comprehensive immigration bill.

“We have a wage-and-cap agreement,” said Sen. Dianne Feinstein, D-Calif.

She is not among the “Gang of Eight” senators drafting the overall bill, but she has worked to help design a program to provide legal status to the estimated 500,000 foreign farmworkers in the country.

Save 75% on a Digital Subscription Today

The eight senators met late Wednesday and signed off on the outline, leaving staffers to work out final details. Senators were optimistic Thursday that a deal was close. “All that’s left is the drafting,” said Sen. Chuck Schumer, D-N.Y., one of the “Gang of Eight.”

If passed, the bill would expand legal immigration, ramp up border security, tighten sanctions against employers who hire people in the U.S. unlawfully and open a path to citizenship for an estimated 11 million immigrants who either entered the country illegally or overstayed their visas.

Border security has been key to the negotiations, and Sen. John McCain, R-Ariz., said that stopping 90 percent of those trying to sneak across the border, as the draft bill requires, wouldn’t be difficult to achieve. He said six of the nine sectors on the Arizona border with Mexico already have 90 percent effective control.

Overhaul efforts got a boost from the U.S. Chamber of Commerce, which is influential with Republican lawmakers. The chamber urged Congress to “take advantage of the unprecedented momentum” and pass an immigration bill this year.

Once the legislation is released, it will be considered by the Senate Judiciary Committee, which has scheduled a hearing for Wednesday. From there, the bill would move to the Senate floor.

In committee and on the floor, the bill could change in unpredictable ways as senators try to amend it. The “Gang of Eight” — Schumer, McCain, and Sens. Dick Durbin, D-Ill., Jeff Flake, R-Ariz., Marco Rubio, R-Fla., Lindsey Graham, R-S.C., Robert Menendez, D-N.J., and Michael Bennet, D-Colo. — have discussed banding together to defeat amendments that could significantly alter the legislation.

Even more uncertain, though, is the conservative-led House, where a bipartisan group is also crafting an immigration bill. Many conservatives in the House remain opposed to citizenship for immigrants who have been living in the U.S. illegally.

Material from The Associated Press is included in this report.