Three nonprofit groups offering homeowner counseling sued Gov. Jerry Brown of California on Friday, demanding the state replace $369 million that had been earmarked to help troubled borrowers but was used instead to pay down the state’s debt.

As part of the $25 billion national mortgage servicing settlement two years ago, California and other states won a portion for home loan counseling and other educational services to help troubled homeowners avoid foreclosure. Kamala Harris, the state’s attorney general, secured the funds after long and tense negotiations with the banks.

But like many other states, California faced financial troubles and diverted funds from the settlement to other uses. In California’s case, it used the money to pay down debt issued by low-income-housing authorities.

Since then, the state’s financial standing has improved significantly; officials project a $4.2 billion surplus this year. Yet the governor has given no indication that he intends to replenish the counseling funds.