The gunman who was shot and killed Monday at New Hope City Hall after wounding two police officers had called court officials earlier in the day, then bought ammunition for the gun he fired that night, authorities said Wednesday.

In laying out a timeline for the confrontation that left Raymond K. Kmetz, 68, dead, Hennepin County Sheriff Rich Stanek also sent out this message Wednesday: "If you fire on a police officer, they are trained to fire back."

Noting that Kmetz had been civilly committed twice for mental health problems, Stanek said, "He should not have had access to any type of weapon."

Authorities do not know how Kmetz got the gun, which the sheriff described as a "pistol-grip shotgun" with the serial numbers "obliterated."

Stanek said Kmetz had called the Hennepin County court system on Monday because he "wanted some property back." The sheriff did not identify the property in question, but earlier court-ordered psychological evaluations of Kmetz have said he believed individuals and government agencies were engaged in various conspiracies against him.

After making that call, Kmetz left his Belle Plaine home, stopped at a store and bought ammunition, Stanek said.

Around 7:15 p.m., Kmetz entered City Hall and "deliberately fired his gun at the officers," Stanek said. Police returned fire, killing Kmetz. It was "over, start to finish, in seconds, just seconds," the sheriff said.

Over the past few years, Kmetz had clashed repeatedly with authorities, particularly in New Hope, often about his longtime and now former home on Nevada Avenue, according to documents and family members. He had addressed the New Hope City Council several times in recent years.

In nearby Crystal, police had filed a restraining order against him in August after Kmetz's family warned police that he had threatened to bring a shotgun to City Hall. The order raised concerns about his increasingly volatile behavior and obsession with city officials.

Kmetz had undergone years of court-ordered mental health treatment and was released from the state hospital at St. Peter in 2013 after being found incompetent to stand trial, according to court documents. A week before his release, the hospital notified the Hennepin County attorney's office that Kmetz was no longer treatable.

The county attorney's office then dismissed several felony charges that had been filed against him in 2009, because his stay at the hospital was longer than a prison term he would have received if convicted. State statute requires that felonies be prosecuted within three years or be dismissed.

Like most defendants found incompetent to stand trial, Kmetz was sent to the Competency Restoration Program at St. Peter, and also was treated at the regional treatment center in Anoka.

The program in St. Peter has 39 beds, which are usually full, according to a state Department of Human Services (DHS) spokeswoman. The program averages five admissions per month, with an average stay of about six months. About 80 percent of those who complete the program are found competent to stand trial.

Kmetz spent more than three years in the program, sometimes failing to take medication and occasionally being given provisional releases when staff determined he was competent. But erratic behavior always sent him back to the hospital, court documents said.

Once an individual completes treatment by being deemed competent, DHS will notify the court that he or she is ready for criminal proceedings. The court then makes the final determination on charges.

If a patient does not achieve competency, Hennepin County can decide whether to pursue continued civil commitment for mental illness. A spokesman for Freeman's office said he didn't know if that option had been discussed in Kmetz's case.

Incompetent, but freed

On Wednesday, Hennepin County Attorney Mike Freeman discussed his office's long involvement with Kmetz, including threats he made to one of his prosecutors. When Freeman's office learned that his mental illness was so profound he was no longer amenable to treatment, the decision was made to dismiss the charges.

Freeman said it's hard to know what the best thing to do is with someone who's released from St. Peter under such circumstances. He said he has been involved in study groups looking at just that question, and hinted the issue may be taken up at the Legislature this year.

"We don't see this scenario very often, but it's really scary," he said. "We need some sort of option to hold these people and keep them off the streets until things are resolved."

He said he was thankful the New Hope officers injured by Kmetz, Beau Schoenhard, 36, and Joshua Eernisse, 30, are home from the hospital and recovering. Schoenhard and others from his department were just leaving a swearing-in ceremony for Eernisse and another officer Monday night when Kmetz opened fire.

The identities of the officers who shot Kmetz have not been released.

New Hope Police Chief Tim Fournier said Wednesday that the officers who shot Kmetz "acted as they should, based on their training. … They took down the threat, protected the environment and secured the building."

Stanek said the Kmetz family is assisting investigators, and "we are thankful for their full cooperation."

Fournier said there is always security at New Hope City Hall, including during council meetings, when "I am present most of the time." He said he was in the building Monday night, along with the officers in the lobby.

City Council Member John Elder is another security safeguard. Elder, a former police officer and spokesman for the Minneapolis Police Department, carries a handgun. As shots were heard Monday, Elder drew his firearm and aimed it toward the door but did not fire.

Staff writer Paul Walsh contributed to this report. Karen Zamora • 612-673-4647 Twitter: @KarenAnelZamora

David Chanen • 612-673-4465