BAILEY, Colo. — Martin Wirth was angry with the system. As a grass-roots activist with the Occupy Denver protests and a long-shot Green Party candidate for a conservative-held seat in Colorado’s Senate, he denounced social injustice and police brutality.

But he had a violent side and nursed a long list of bitter grievances: He said the police were harassing him because he was a “high-value target,” and he railed against a banking and judicial system that foreclosed on his home in a snowy mountain subdivision called Friendship Ranch. He had a long string of run-ins with the police — whom he compared to “assassins” — and a neighbor said he used to threaten anyone who might try to remove him from the house.

On Wednesday, when seven Park County sheriff’s officers arrived to serve what they called a “high-risk” eviction notice to Mr. Wirth, meaning they knew he might try to retaliate, he opened fire on them, killing a corporal who had grown up in the area and coached baseball at a local high school. Two other officers were wounded, one of them critically. Mr. Wirth, 58, was shot and killed by the officers.

“This is one of those things that should not have happened,” Sheriff Fred Wegener said Thursday by the side of the road as a cortege carrying the body of the slain officer, Cpl. Nate Carrigan, prepared to pass. “We were going to tell the individual, ‘Time’s up, you need to move out.’ We were simply there to do our job.”

Sheriff Wegener said that Mr. Wirth had come out on his deck as officers arrived to deliver the eviction order around 10 a.m. Then Mr. Wirth went back inside, and when officers followed him into the house, he began firing, Sheriff Wegener said. Master Patrol Deputy Kolby Martin was struck multiple times, and Capt. Mark Hancock was grazed in the ear. Sheriff Wegener described Corporal Carrigan as “one of my kids,” who had a fiancée and four stepchildren. People around Bailey recalled him as a caring man and a dedicated coach.

The killing stunned this town an hour southwest of Denver. Few people here said they had known Mr. Wirth. In a place where some residents meet every morning for coffee at the Cutthroat Cafe while others seclude themselves in the mountains, people said Mr. Wirth seemed to fit the second description.

The battle over Mr. Wirth’s foreclosure and eviction had unspooled for years in court filings and legal confrontations. On Thursday, Sheriff Wegener said law enforcement officers had been concerned about serving the eviction notice because of previous run-ins with Mr. Wirth.

Mr. Wirth had racked up a string of traffic violations and an intoxicated driving charge over the years, and in 1994 had been accused of fatally shooting a neighbor in a northern Colorado trailer park after getting angry over losing a game of chess. He was acquitted of second-degree murder in the case, which is now sealed, according to The Coloradoan newspaper of Fort Collins.

“He was kind of anti-establishment, anti-authority, ‘I can do what I want,’ ” said Terry Rogers, a neighbor who is also a local pastor and helped lead a community vigil the night of the shooting.

The home went into foreclosure in 2013 and Mr. Wirth lost ownership; he unsuccessfully suing in federal court to keep the house. When officials tried to evict him in 2014, he sought help from the Colorado Foreclosure Resistance Coalition, a grass-roots group that helps homeowners in foreclosure. The group rallied to his case but called off plans to carry out a peaceful “eviction resistance” protest at his home in 2014.

“We became worried that he may bring a weapon back on the property,” said Steve Bailey, a leader of the group.

Some activists who knew Mr. Wirth through his protest involvement or his Green Party candidacy said he was peaceful and committed to issues of justice, and offered words of grief for his death. But those sentiments outraged some in Bailey, who said the officers and their families were the only ones who deserved sympathy.

“We’re all family here,” said Dave Judish, as he sipped coffee at the Cutthroat Cafe on Thursday. “It makes us so mad, we can’t see straight.”

A version of this article appears in print on , Section A, Page 14 of the New York edition with the headline: Facing Eviction, Man Kills an Officer. Order Reprints | Today’s Paper | Subscribe