WASHINGTON – Agreement was reached late Friday between farm labor unions and growers on one of the last major components of a sweeping immigration bill being drafted in the Senate — a deal that would set the terms of wages, visas and working conditions for migrant agriculture workers.

The accord, struck after weeks of touch-and-go talks between representatives of industry leaders and workers and brokered by Sen. Dianne Feinstein, D-Calif., would establish a new "blue card" for migrant workers already in this country without legal permission, and allow up to 336,000 visas for farmworkers.

The three-part package is hugely important for California's agriculture industry. It will be folded into a comprehensive immigration overhaul being written by a bipartisan group of eight senators, who are aiming to introduce the far-reaching legislation as soon as Tuesday.

Feinstein, who is not one of the eight, led the farmworker effort with Sen. Marco Rubio, R-Fla., and Sen. Michael Bennet, D-Colo., who are part of the broader group, and Sen. Orrin G. Hatch, R-Utah, her longtime partner on agricultural worker immigration issues.

"All have come together to endorse this agreement," Feinstein said in a statement announcing the deal.

Talks had been underway for months, but hit a logjam as ­growers pushed for lower wages and fewer limits on visas and farm labor unions sought higher wages and visa caps.

Ultimately, growers achieved both their goals, with more visas and slightly lower wages than in earlier offers, according to two sources familiar with the talks. In exchange, labor leaders secured a longer visa and requirements that growers pay housing and transportation costs.

Both sides saw the final product — for an industry in which as many as half of the 1 million workers nationwide are in the country without legal permission — as a ­compromise.