Still, some local residents are skeptical.

Giles Thelen, a plant ecologist at the University of Montana in Missoula, said that results of the sheep grazing program were anecdotal and that plots should be used to measure how effective the sheep were. Mr. Thelen also worries about the sheep worsening the problem by picking up invasive seeds in their wool and dropping them in new areas, as well as causing erosion with their hooves.

“There’s no data to show if the sheep are making the situation worse or better,” he said. Some herbicides may be more effective, he said, “but people don’t like poison on their public lands.”

Image The owner of the sheep, John Stahl, helped lead them back to his ranch. Credit... Janie Osborne for The New York Times

Each year, the city contracts with John Stahl, a fourth-generation rancher who drives his flock to the infested hills from his Missoula County ranch nine miles away.

The city pays Mr. Stahl about $1,300 a month, including a modest stipend for Mr. Marquez. The rancher provides Mr. Marquez’s food, equipment, camp wagon and bus fare from his home in Chihuahua, Mexico.

Mr. Stahl said access to the forage on public lands allowed him to continue raising sheep and other livestock instead of selling the ranch to developers.

“I couldn’t make a living on the sheep without access to the city land,” Mr. Stahl said. “And Enrique really knows the sheep and all the places they can hide. He has an instinct for animals.”