A bill to ban publicly funded abortions for all women except whose lives are endangered by pregnancy is wending its way toward enactment by the Massachusetts legislature.

If finally passed and signed into law by Gov. Edward King, it would give one of the nation's most politically liberal states one of the most restrictive abortion statutes. Only North Dakota's recent anti-abortion law is more restrictive. It has a provision prohibiting the payment of public funds to anyone who performs abortions or even "refers or encourages" them.

The proposed new Massachusetts law, given initial Senate approval Wednesday on a 21 to 16 vote after House approval, forbids the use of state or any other public funds for abortions for victims of rape or incest, which is permitted under current law.

For the first time in state history, abortion aid will be denied public school teachers, municipal workers, county employes and others protected by state-supported group health insurance plans as well as welfare recipients and state employes covered by the Massachusetts Group Insurance Commission.

The new regulations will also affect prisoners, retarded persons and mental patients - in short all women who rely on the state to pay their medical bills.

"This is one of the worst abortion laws in the country," said Nancy Gertner, an attorney for the Massachusetts chapter of the American Civil Liberties Union.

"The legislature's decision not to allow victims of rape and incest to get publicly funded abortions is nothing short of idiotic - morally and legally," she said. "They are making a mockery of the federal court system which has ruled against these kinds of regulations."

State Sen. Alan D. Sisitsky called the new curbs "barbaric and unconscionable."

Countered Sen. Joseph B. Walsh: "Sisitsky is one of the civil libertarians who would protect murderers but who have no concern for the life of the fetus. That's a living, breathing fetus they want to destroy."

Added Boston City Councilman Raymond L. Flynn, a leader in the antiabortion fight, "the Senate's vote is a clear reflection that the people of Massacchusetts only want their tax dollars spent on meaningful social programs to assist needy people rather than on a regressive and unconscionable policy of destroying unborn children."

The legislation needs only a perfunctory second round vote by both houses before it can go early next week to the governor, a conservative Democrat who campaigned against abortion last year in his first try at elective office.

In an apparent political paradox, the North Carolina House voted 72 to 42 continue full Medicaid funded abortions for poor women at the same time the Massachusetts Senate passed the new abortion measure.

"It's ironic that within the space of a week, a state like North Carolina which is generally considered conservative would maintain its funding for Medicaid abortions while an ostensibly liberal state like Massachusetts would do this kind of thing," said Karen Mulhauser, executive director of National Abortion Rights Action League, a Washington-based lobby.

The new law, however, may not go into effect immediately because a suit filed by the Massachusetts chapter of the American Civil Liberties Union challenging abortion restrictions enacted last year is pending at the U.S. Supreme Court. Justice William Brennan issued an injunction against enforcement of the 1978 measures.

State Rep. Charles Doyle, who led the drive of 30 legislators in sponsoring the antiabortion bill, predicted the new will propel Gov. King into the national limelight because of his strong and repeated stands on abortion.

"This will make the governor of Massachusetts a national figure and one of the most prominent governors in the country," he said. "There's no one who is stronger pro-life than the governor of Massachusetts."