SAN GABRIEL, Mexico  In the past, farmers would make the dangerous trek north from this tiny town hidden in the rugged folds of the Jalisco mountain range to the United States, hoping to earn enough money doing odd jobs to cover debts incurred while cultivating the small plots of land that have been in their families for generations.

But more recently, many have managed to avoid the trips, staying home as the result of a new venture with PepsiCo, which buys their crops.

“Some of us used to go north to work to make money to pay off debts, but no longer,” said Martín Ramos Torres, a farmer, adding that at least two members of the cooperative he leads had been caught by United States border patrol agents and deported. “In just three years, everything has changed.”

Mr. Ramos and some 300 small farmers here no longer sell their corn to middlemen but directly to PepsiCo, which guarantees the price it will pay for their crops upfront. The deal enables the small farmers to secure credit to buy seeds and fertilizers, crop insurance and equipment.