After watching a growing series of tents and other makeshift shelters spread into city parks and sidewalks, officials in northwestern Montana decided it was time for a crackdown on homelessness.

In Kalispell, city leaders approved an ordinance to punish motorists who give money or supplies to panhandlers. They shut off water and electricity at a city park where some were seeking refuge. The county commissioners wrote an open letter to the community early last year, warning that providing shelter or resources to homeless people would “enable” them and entice more of them into the area.

“It is our hope that our community will be unified in rejecting all things that empower the homeless lifestyle,” the commissioners wrote.

But in the year since that call to action, the purge effort has done little to resolve a problem that is still apparent — even now amid the frigid depths of winter — on the streets of a city better known as a gateway to scenic ski slopes and Glacier National Park.

Homeless residents said the city’s letter unleashed a punishing public backlash, with many reporting that groups of young people were roaming through homeless encampments and tormenting those living there. Many of them are longtime locals displaced by the skyrocketing housing costs that have plagued the Flathead Valley, where Kalispell lies, along with other towns of the Mountain West.

Christina Nelson, 57, a lifelong resident of the Kalispell area, said she became homeless after a divorce in 2021. Over the summer, she said, while she and another person were resting on a bench outside the mall, a group of teenagers or young adults pulled up in a white car and began throwing eggs at them. “Go home, you lazy bastards,” she recalled them shouting.

Patty Archambault, 62, who has lived her whole life in Montana and in Kalispell for 12 years, became homeless about a year ago when she and her husband, both dealing with illness, fell behind on rent. This past summer, as they lived in a tent on the edge of a city park, she said, a group of young people approached in the night and fired paintball guns at them, leaving them with welts. “They said they don’t like the homeless, they want us out of their town,” she recalled.

Victor Parra, who has lived in the Flathead Valley for many of his 44 years and became homeless last year, said he was roused from his tent one night by an aggressive crowd. One person punched him, he said, while another pointed out a rope that he wanted Mr. Parra to tie to a tree. “We’re going to hang you up,” one of the people told him. Mr. Parra said he eventually got them to back down by agreeing to leave the area, and he ran from the park.

Stories of similar confrontations were already spreading when the end of June brought a new level of threat. In the early morning hours, police officers found a homeless man, Scott Bryan, 60, lying behind a gas station, his head so severely beaten that bone was exposed and his nasal cavity appeared to have been crushed. Mr. Bryan was later pronounced dead, and a 19-year-old man was arrested, charged with deliberate homicide.

Many in the homeless community had known Mr. Bryan personally, said Tonya Horn, the executive director of the Flathead Warming Center, a shelter that offers overnight beds during cold months. Homeless residents were advised to stick together, but they continued to encounter threats.

The Police Department received a wide range of reports about harassment of homeless people, said Police Chief Jordan Venezio, including some cases of fireworks being shot toward people. In a lot of cases, he said, officers were unable to find suspects or get much cooperation from homeless residents in identifying them.

Ms. Horn said the letter sent by the county commissioners at the start of 2023 had set the stage for the public animosity.

“The words painted a picture that the homeless are not from here, that they are not our neighbors, so we should not take care of them,” Ms. Horn said. “It was dehumanizing.”

The Flathead Valley, surrounded by verdant forests and clear lakes, has long been a haven for those resisting change from the outside world. The region has grown more politically conservative in recent decades, drawing militia groups and others seeking to establish a conservative Christian stronghold in the remote interior amid the nation’s shifting political and cultural landscape.

The mountainous region, speckled with cabins and small ranches outside the cities, offered affordable refuge and isolation. But in recent years, as the pandemic drove a growing number of urbanites into wide open spaces like northwest Montana, the cost of living soared, and so did homelessness.

Locals warned that Kalispell could fall victim to the problems of public drug use and crime that were afflicting bigger cities. On Facebook, some residents gathered in community groups to swap stories and videos about homeless people; some encouraged carrying guns for protection.

“Sad to say but with more people coming to the valley also comes more crime and unwanted behavior from individuals,” one person wrote. “Carry everywhere.”

As in many cities, some residents warned that offering services to the unhoused would entice homeless people to travel in from elsewhere.

But Ms. Horn said 90 percent of those getting services in Kalispell had been in Montana for at least a year. If there had been a migration of homeless people into the area, Ms. Horn said, she would have been the first to speak up because the region does not have enough resources to fully help those who are already there.

Randy Brodehl, a county commissioner who helped pen the letter calling for community members to stop supporting the “homeless lifestyle,” said he stood by the message. The rise in homelessness, he said, has brought theft, encampments and drug paraphernalia left in city parks.

“When you give somebody an opportunity to live for free and let somebody else pay for your costs, people are going to take advantage of that,” he said.

Advocates for the unhoused said a range of problems have led to homelessness in a place where it previously was not prevalent. Housing costs shot up. Funding cuts from the state several years ago gutted case management programs for people with severe mental illness and addiction. Several hotels that had been available for long-term stays, a temporary solution for those between more permanent housing slots, closed.

Travis Ahner, the top prosecutor in Flathead County, said it was clear that the area needed more mental health and addiction treatment services. He also said the cost of living has become so high that even lawyers his office tries to hire decide not to pursue the job once they realize they cannot afford housing.

“There is not an easy way out,” he said.

With the onset of a bitter Montana winter, the situation for the unhoused has been difficult at best. Some people have had to undergo amputations as a result of frostbite. Some are sleeping in cars and shelters while working in town.

Dozens line up each evening outside the warming center, which opened in a converted car mechanic garage. On many nights, people are turned away into the frigid night because of capacity constraints.

“I don’t want to be here,” Jessica Taylor, 45, said as she arrived at the shelter one night in December. She had grown up in a well-off family in the area and recently lost her retail job when she had an extended illness. She tried sleeping in her car, then eventually ended up at the warming center.

On her first night there a few months ago, she got out of the car, saw the line of people waiting to get inside and broke down in tears. It was not the type of place people like her should ever stay, she thought. But she went in and curled up on one of the bunk beds.

“I just cried and cried and cried and cried,” she said. The experience at the shelter, she said, has helped her realize that she had been too judgmental of the homeless people she had seen around town.