BOSTON, AUG. 18 -- The Massachusetts Supreme Court ruled today that welfare families must receive enough money to allow them to remain in their homes, a decision the state says could cost $780 million a year.

The ruling was hailed by welfare activists who say Massachusetts benefits are 40 percent below the federal poverty line.

The decision came in a suit by the Massachusetts Coalition for the Homeless and the Massachusetts Coalition for Basic Human Needs.

The groups contended a 1913 state law requires the Department of Public Welfare to provide benefits under the Aid to Families with Dependent Children program that allow welfare families to live in their own homes.

The administration of Gov. Michael S. Dukakis (D) had argued that raising benefits to the cost of living in Massachusetts, as determined by the department, would add $780 million a year to the $500 million state welfare budget.

About 500 of the state's 84,000 welfare families live in hotels, motels or shelters, an official said.

According to a report compiled last August by the department under court order, the average family of three in private housing in Boston needed at least $11,117 a year to live, or double the welfare benefits of about $5,700 at that time.