The difficult case of Igor Perlov began last year when, authorities said, he called the FBI in San Francisco to say he thought there was a chip under his skin and was being programmed to carry out a mass shooting.

When police learned he had guns — including a legally possessed rifle with a scope they found next to a window overlooking a school — officers acted swiftly, placing the 31-year-old man on an involuntary psychiatric hold.

Now eight months later, he’s out of the hospital and in jail. He’s awaiting trial on one charge of unlawful possession of ammunition in a case that highlights a challenge for San Francisco and other cities: How to deal with a person authorities believe presented a risk of hurting others, but who hasn’t committed a serious crime.

For his part, Perlov denies having mental illness and says he’s no danger. He said he had guns and ammunition because he is an “enthusiast,” and planned to start a business selling firearms and accessories. The case, he said, has been blown out of proportion over “some stupid stuff that I said” while high on methamphetamine.

“When cops ask stupid questions, sometimes you just try to be a smart-ass, and that’s what got me in trouble — my foolishness,” Perlov said in a recent interview at San Francisco County Jail in San Bruno. “It’s funny. People will believe anything you tell them and take everything so seriously.”

There’s no question the FBI took Perlov’s Aug. 17 message and four subsequent calls over the next month seriously. The communications raised enough concern with federal agents that they contacted San Francisco police.

When members of the Police Department’s crisis intervention team went to Perlov’s home in the Richmond District in September, they said they found more cause for alarm.

Not only did he say he was still hearing voices, police said, he had five guns — all of them legally possessed. Officers seized four handguns stowed in the trunk of his car, officials said, before a search of his second-story apartment turned up a .308-caliber bolt-action rifle with a scope leaning next to a window overlooking Katherine Delmar Burke School, a private K-8 all-girls school.

Police said they did not find evidence that Perlov was planning an attack, and no threat was made against any specific location or person.

“I looked at the totality of what we were dealing with — someone saying they’re being told to commit a mass shooting, that they have a chip implanted, and that they had several firearms,” Officer Carlos Manfredi testified at a recent hearing in San Francisco Superior Court. “There was a growing concern for safety because I didn’t know what I was dealing with.”

Manfredi contacted the city Department of Public Health, which placed Perlov on an involuntary psychiatric hold, commonly known by the state legal code 5150, at UCSF Medical Center. Under California law, people can be involuntarily hospitalized up to 72 hours if they’re deemed dangerous to themselves or others. Perlov was considered a danger to others.

If a person continues to be a risk, he or she can be held longer. Perlov said he was held for two weeks. He faced no criminal charges, so he was sent home, where he lives with his mother and stepfather. He was banned from possessing guns or ammunition under a California law designed to keep firearms away from people deemed a danger to themselves or others as a result of a mental health disorder.

But in December, San Francisco police got a call from law enforcement in Quartzsite, Ariz., saying they pulled Perlov over and found 500 rounds of ammunition in his car. Perlov told The Chronicle he was in Arizona visiting a monastery where he was getting clean. He said he hasn’t used methamphetamine since.

After he returned home, San Francisco police visited him and said they found more than 700 rounds of ammunition in his car and apartment. Officers arrested him, and he’s now being held in lieu of $100,000 bail awaiting trial on the ammunition possession charge.

If he is convicted, he faces a sentence of 16 months to three years in prison. Perlov does not have a criminal record and is earning double credits for time served as he awaits trial.

The Chronicle learned of Perlov’s case in the course of covering court hearings at the Hall of Justice. Police officials did not reveal it publicly, nor did they tell administrators at Katherine Delmar Burke School, who did not know about the case until contacted by the newspaper.

“We have been in touch with SFPD about this matter, and they have advised us that the individual involved has been in custody for several months, and that law enforcement and mental health professionals did not contact the school because they did not believe that our school was a point of interest for this individual,” Michele Williams, the head of school at Katherine Delmar Burke, wrote in an email to The Chronicle.

She added that police are “committed to notifying the school before he is released and working with us on a safety plan. Nevertheless, we are concerned that an individual with mental health problems living in the school’s neighborhood was able to acquire weapons.”

Perlov sits at a tricky intersection of the city’s criminal justice and behavioral health systems. Under state law, he can’t be forced into long-term psychiatric treatment unless he’s found to be so mentally ill that he can’t function on his own.

Psychiatrists previously diagnosed him with having an unspecific schizophrenia spectrum disorder or other psychotic spectrum disorder, according to recent court testimony by Dr. Courtney Thomas, who works in crisis services with the Department of Public Health.

“The way that mental health law is set up, you can’t compel someone to take medication long term on the basis of them being dangerous,” said Dr. Paul Linde, a San Francisco psychiatrist who worked in the psychiatric emergency room at San Francisco General Hospital for 24 years.

Linde, who is not involved in Perlov’s case, said mental health conservatorship laws are designed for people with grave disabilities who are not able to care for themselves — not for people deemed potentially at risk of hurting someone. A conservatorship gives a person the legal authority to make certain decisions for another person, including compelling mental health treatment.

There are encouraging aspects of Perlov’s case, said his attorney, Deputy Public Defender Mark Iverson. He has cooperated with police in the past. He will be prohibited from owning a gun. And police didn’t find evidence he was planning an attack. What’s more, Perlov said this is the first time he’s ever been in jail.

But the facts leading to his arrest have left San Francisco authorities uneasy.

Iverson asked a judge to release Perlov on electronic monitoring before trial, a common practice for defendants facing similar or even more serious charges. The ammunition police found in December, Iverson said, had been in Perlov’s car and home before his guns were seized. Judge Kay Tsenin, though, denied the request, saying she was uncomfortable with anything less than keeping him in custody in lieu of bail.

Iverson said the prosecution and judges are “frozen in their decision-making” on the case, even though the charges don’t warrant a significant long-term punishment.

“Any person who can lawfully have a gun can have it at their window whether they’re across from a school or not,” he said. “That’s the world we live in.”

Another concern for Iverson is Perlov’s housing in County Jail, where around 15% of the population has serious mental health issues, according to a 2016 report by the city’s Budget and Legislative Analyst’s Office. The lawyer said his client isn’t getting the help he needs while behind bars.

“My client should be getting mental health treatment, but he’s in jail,” Iverson said. “A lot of people have nobody. He has a family. He has resources, which normally is a good sign for future behavior.”

The city does have the ability to try to steer jail inmates toward managing their mental health. Prosecutors and judges can use several tools, including Behavioral Health Court, which connects defendants with serious mental illness to treatment services as a way to resolve their charges.

Similarly, the state’s new mental health diversion law authorizes a court to grant pretrial diversion for a defendant who has a mental disorder and prefers treatment to going in front of a jury.

But even in those cases, the defendant must be willing to participate, and attorneys and judges must agree that the program is a good fit. Perlov is not currently in any of these programs. Officials with the district attorney’s office said they could not comment on the case.

“In every case, we strive to obtain the best outcome for all parties involved given the circumstances,” said Alex Bastian, a spokesman for the district attorney’s office.

A judge also can mandate that a person get services and take medication under the terms of their probation when they are released, or risk going back to jail.

“For some individuals, having pending criminal charges helps support them to accept those services,” said Angelica Almeida, director of Forensic and Justice Involved Behavioral Health Services with the city health department. “Having a host of options can be really beneficial.”

Perlov doesn’t believe he needs medication. He told The Chronicle he had heard voices, but said they would come amid days-long meth benders in which he wasn’t sleeping and was “a little paranoid.” He couldn’t say why officials held him for two weeks on the involuntary hold last year.

He is currently housed among the general population in jail and said he has stopped taking psychiatric medication, which he said made him drowsy.

“I don’t like how they’re trying to label me as gravely disabled and a danger to others,” he said. “That is just a false accusation, you know? This is just not me, and I don’t want to be labeled as that. That’s why I’m trying to fight this case.”

Iverson said his client’s calls to the FBI were an effort to get help and an indication that he would be willing to accept it when released. After the first call to the FBI in August, Perlov said his follow-up messages were to find out how he could dispose of “parts for automatic weapons” he bought at a gun show at the Cow Palace.

California has safeguards preventing some people deemed to present risk from having firearms. Existing law bars anyone who has been found to be a danger to themselves or others from possessing a gun for five years. Under a new law that takes effect next year, anyone found to present such a danger twice in one year is banned for life.

Upon release, Perlov may return to his home across from the Katherine Delmar Burke School. He said he will go back to the carpentry and concrete work he was doing before he was arrested. Perlov insisted he never had any plans to commit violence and said the case against him is “bogus.” When released, he said he will stay away from guns and drugs.

“I was never a dangerous person,” he said. “I despise violence myself. This is the stuff that actually bothers me. That’s why I called the FBI, because this bothers me. I’m worried about it.”

His stepfather, George, who did not give his last name, said he hopes Perlov will return to the family’s home when released, but said, “We can’t push him to do it. He’s an adult, and he has a legal right to make any decision.”

Evan Sernoffsky is a San Francisco Chronicle staff writer. Email: esernoffsky@sfchronicle.com Twitter: @EvanSernoffsky