EL MIRAGE, Ariz.— For the last two seasons, G Farms has depended on legal migrant workers to harvest potatoes, onions and watermelons growing in its fields on the outskirts of Phoenix.

Now the farm is bearing different fruit: a first-of-its-kind federal lawsuit that federal officials and immigration activists say exemplifies the pitfalls of the nation’s agricultural visa program—as Congress proposes changes to it.

This...