When California received $410 million in 2012 as part of a nationwide settlement with major banks accused of abusive foreclosures, Gov. Jerry Brown used $331 million to pay state agencies in housing and other programs to cover their deficits.

Now a state appeals court has ordered the money be used for its original intent: to help homeowners who suffered foreclosures.

The money was “unlawfully diverted” from a settlement fund that was designated for programs directly assisting homeowners, the Third District Court of Appeal in Sacramento said Tuesday. A Sacramento County judge had reached the same conclusion but found he lacked authority to order the state to redirect the money, a finding the appeals court rejected.

Neil Barofsky, a lawyer for the National Asian American Coalition and other groups that filed the suit, said the court had properly ordered the state to “immediately put the money back into a fund where it can be used to help struggling homeowners,” particularly in poor and minority communities.

H.D. Palmer, spokesman for Brown’s Finance Department, said state officials had not decided whether to ask the California Supreme Court to review the case. He said the debt payments, most of them for housing bonds, had been approved by state lawmakers, and the case raised questions about whether “the Legislature’s appropriations power can be overridden with a court judgment.”

The nation’s five largest mortgage servicers — Bank of America, Wells Fargo, Citigroup, JPMorgan Chase and GMAC — reached the settlement in 2012 in a suit by the federal government and every state except Oklahoma. It included more than $20 billion in direct aid to foreclosed homeowners and $2.5 billion to the states, including $410 million to California.

Of the $410 million, at least $331 million was designated by then-state Attorney General Kamala Harris for a fund devoted to programs assisting homeowners who were harmed by the wave of foreclosures. The programs included housing counselors, foreclosure assistance hotlines, legal aid, consumer education and efforts to investigate and combat financial fraud.

After the fund was established, however, the state’s Finance Department appropriated the money, with legislative approval, to pay off deficits to the state agencies in charge of state housing bonds and other consumer-related measures. State lawyers argued that the payments were consistent with the mortgage settlement and were not subject to judicial review, but the court disagreed.

The money “was unlawfully diverted from a special fund in contravention of the purposes for which that special fund was established,” Justice Andrea Hoch said in the 3-0 ruling.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter:@BobEgelko