MOOSE LAKE, Minn. – Keeping sex offenders locked up in treatment after they finish their prison sentences emerged as a popular get-tough tactic in the 1990s, when states were flush with cash. But the costs have soared far beyond what anyone envisioned.

An Associated Press analysis found that the 20 states with so-called “civil commitment” programs will spend nearly $500 million this year alone to confine and treat 5,200 offenders still considered too dangerous to put back on the streets.

The annual costs per offender topped out at $175,000 in New York and $173,000 in California, and averaged $96,000 a year, about double what it would cost to send them to an Ivy League college. In some states, like Minnesota, sex offender treatment costs more than five times more than keeping offenders in prison. And those estimates do not include the considerable legal expenses necessary to commit someone.

The programs have created a quandary for lawmakers who desperately need to cut spending in the midst of a recession but don’t want to be seen as soft on rapists and child molesters.

“I’ve heard people in a lot of the states quietly say, ‘Oh, my God, I wish we’d never gotten this law,’” said W. Lawrence Fitch, a professor at the University of Maryland School of Law. “No one would ever dare offer repeal because it’s just untenable.”

The laws target sex offenders who are considered likely to strike again. When one of them is close to finishing a prison sentence, prosecutors file a civil case to prove that person still threatens the public and needs treatment. If the court agrees, the prisoner is committed in much the same way that someone with a serious mental illness would be sent to an institution.

The heavy financial burden of treating confined sex offenders has left lawmakers with less money as they make agonizing cuts to areas such as education and health care. Politicians who spent years cracking down on sex crimes now struggle to pay for their tougher laws.

“It’s easy to say, ‘Lock everybody up and throw away the key,’ ” said state Rep. Michael Paymar, a St. Paul Democrat who heads a public safety budget panel. “But it’s just not practical.”

The laws have withstood legal challenges all the way to the Supreme Court. They are considered constitutional as long as their purpose is treatment, not detention. But living up to that standard can cost far more than traditional prison. And the costs persist for years because most inmates will never be released.

The programs have given rise to new and bigger treatment centers: California opened a 1,500-bed facility for sexual predators in 2005. Minnesota opened a 400-bed building last year and plans another expansion at Moose Lake, 110 miles north of the Twin Cities.

In most states, the number of confined sex offenders has steadily increased, requiring ever-greater spending.

• Iowa spends nearly $7 million to confine 80 offenders, almost double 2005′s $3.6 million budget for 48 patients.

• Virginia’s program has swelled from 45 patients five years ago to more than 200 this year, with annual costs climbing from $10 million to almost $16 million.

Some states have steered clear of the civil-commitment system, partly because of financial reasons. In Louisiana, legislation died last year after top lawmakers questioned the cost and constitutional issues. Vermont legislators rejected a similar proposal.

There is also the continuing debate about whether psychological treatment of sex offenders has any real effect on making predators less threatening.

Fitch, the Maryland expert, said research suggests that treatment lowers their risk of committing more sex crimes only slightly, something less than 20 percent. He said states without civil commitment for sex offenders tend to focus on controlling behavior more than psychology. Colorado, for example, manages them through intensive supervision, lie-detector tests, tracking devices and counseling.

Not all civil commitment programs are financially strained. The cost of Arizona’s system actually dropped slightly in the last five years. In Wisconsin, the Sand Ridge center has expanded gradually without any outcry about the money involved.

Wisconsin has released 61 sex offenders since adopting a civil-commitment system in 1994. But in Minnesota, no one has ever gotten out. One man was released provisionally but got pulled back for a technical violation and later died in confinement.

“Are Minnesota sex offenders that much more dangerous than Wisconsin sex offenders? Why can’t we do that?” asked Eric Janus, an expert on civil commitment who heads William Mitchell College of Law in St. Paul.

Missouri and Pennsylvania have released one patient each. Nebraska has released just one person since 2006. Texas has yet to release anyone from its outpatient program.

That compares with states such as California, which has put nearly 200 offenders back into the community, and New Jersey, where 123 have been let go.

Minnesota’s law was passed in 1994 after the state Supreme Court overturned the commitment of Dennis Linehan, a repeat sex offender who had served 27 years in prison for kidnapping a 14-year-old baby sitter found strangled in 1965.

After public outrage, then-Gov. Arne Carlson called the Legislature into a one-day special session to broaden the civil commitment statute. Linehan was swiftly recommitted.

The program grew steadily over the next decade, then exploded after the 2003 abduction and slaying of Dru Sjodin, a 22-year-old North Dakota college student, by a Minnesota sex offender. The suspect, Alfonso Rodriguez Jr., had been freed after finishing a 23-year sentence for an attempted abduction. Prison authorities did not recommend civil commitment.

After Sjodin’s murder, state prison authorities began referring all high-risk sex offenders for commitment. The program’s population jumped from 167 in 2000 to 565 this year. It is projected to reach 1,000 in six or seven years.

Paymar, the St. Paul lawmaker, said he would like to see the state move toward a system of indeterminate criminal sentences for sex crimes, giving prison authorities more discretion over when to release sex offenders who might otherwise be candidates for civil commitment.

Even as he questioned Minnesota’s spending, Paymar chose his words carefully.

“No one wants to be — certainly here in this body — perceived to be soft on sex offenders,” he said.

In California, Assemblyman Nathan Fletcher echoed that sentiment, saying public safety trumps any discussion of the expense of civil commitment.

Fletcher, a Republican, represents a San Diego district where 17-year-old Chelsea King was raped and murdered by a convicted child molester in February. The offender, John Albert Gardner III, also raped and murdered 14-year-old Amber Dubois near Fletcher’s district.

“At the end of the day,” Fletcher said, “you have to keep them incarcerated whatever the cost.”