Stung by the crash of the housing market, some struggling homeowners are using a little known but increasingly popular provision of the bankruptcy code to eliminate second mortgages and avoid foreclosure.

Statistics are hard to come by, but bankruptcy lawyers say the provision has been used effectively on hundreds, if not thousands, of cases in the Bay Area during the past two years.

“It’s a big thing in our valley,” said James “Ike” Shulman, a San Jose bankruptcy lawyer. “But it’s not widely known.”

Shulman, co-founder of the National Association of Consumer Bankruptcy Attorneys, said he has helped a number of clients who have filed for personal bankruptcy use the law to hold on to their houses — including three last week.

Cathy Moran, a Mountain View bankruptcy lawyer, said one of her clients had a $132,000 second mortgage voided by the court.

“This is a really big-ticket issue that allows people to keep a home and conform the mortgage to something closer to real value,” Moran said.

Bankruptcy laws prevent homeowners from eliminating the debt of a first mortgage if they plan to stay in their home. But second mortgages are treated differently. They can be declared unsecured debt when there is no equity to cover them, as is the case for millions of houses that are now worth far less than a few years ago.

When that happens in a personal bankruptcy proceeding, the second mortgage is put on hold and no payments are required while the homeowner completes a repayment plan for other debts — which typically takes three to five years. At that point, the second mortgage is eliminated.

Many of these second mortgages were granted during the housing bubble, when home prices were going in one direction only — up, up and up.

“A lot of these are loans that shouldn’t have been made at all,” said Henry Sommer, editor of Collier on Bankruptcy, a publication on bankruptcy law.

One of Shulman’s clients, Veronica — who asked that her full name not be used — was struggling to keep the San Jose house she bought in 2005 for $612,000.

Her home’s value has dropped to about $367,000 — less than her first mortgage of $489,000 — which allowed her to petition the bankruptcy court to set aside her $122,000 second mortgage. The court granted her motion.

She successfully completed her payment plan for other debts two months ago, and her second mortgage is now eliminated.

“It’s wonderful,” she said. “After almost six years, I am finally able to see the light at the end of the tunnel and I’m so, so grateful.”

Mortgage bankers don’t like the practice.

It’s “a troublesome phenomenon. It’s one of those things that’s just now developing and bubbling up,” said Dustin Hobbs, spokesman for the California Mortgage Bankers Association. But there is little the mortgage industry can do, aside from seeking to change the law. That could be difficult given the current partisan lineup in Washington.

And there are no complaints from investors in first mortgages, like the pension and retirement funds represented by the Association of Mortgage Investors. “We think with the right controls, something like this to allow a responsible, distressed homeowner to reorganize their assets, liabilities and cash flows is a very pro-business proposition,” said Chris Katopis, the association’s executive director. “We disagree with what the mortgage bankers associations are saying on this.”

The law has been like this for years, bankruptcy lawyers say. It’s just never been used as much because in the past there was usually enough equity in a home to cover the second mortgage.

“We’re having great results” using the rule, said Brette Evans, a San Jose bankruptcy lawyer. In one recent case, a small-business owner was able to hang on to her home by setting aside a $240,000 second mortgage, she said.

That put the borrower in “a safe zone” where she could work out a modification of her first mortgage, Evans said.

Contact Pete Carey at 408-920-5419.