EJIDO RANCHO OJO LAGUNA, Mexico — For six years, while drought ravaged Chihuahua State, Mario Ruiz clung to his small herd of cattle.

The pasture where his cattle graze, about 45 miles north of the city of Chihuahua, turned bare. Many of his cows starved. Others he sold to buy fodder for those worth saving. Of 130 cows, just 30 are left.

Now that the rains have returned, turning the dusty steppe a rich green, farmers like Mr. Ruiz, 41, are struggling to restock their herds and dig themselves out of debt. They fret that the drought, which devastated crops and killed 400,000 head of cattle in Chihuahua State, just south of the United States border, could become a familiar enemy.

“If it rains, we’ll survive,” Mr. Ruiz said. “But it seems like it rains less and it rains later.”

Faced with the growing threat of extreme weather — droughts, hurricanes and rising coastal waters — Mexico has positioned itself as a leader in the fight against climate change. It pledges to curb the rise in emissions significantly by 2020 and to produce one-third of its energy from clean sources by 2024.