Spain's Roman Catholic Church and conservatives have closed ranks to oppose plans by the country's new Socialist government to lift existing harsh bans on abortion, permitting the operation in certain restricted cases.

Socialist officials privately conceded today that the abortion issue constituted the first major test of public support for Prime Minister Felipe Gonzalez's two-month-old government.

Church congregations yesterday heard priests speak out strongly against the Socialist proposal. In one large Madrid church, filled with middle-class parishioners, the congregation was urged to demonstrate in the streets against abortion.

A statement issued by the secretary of the Spanish bishops' conference, Msgr. Fernando Sebastian, termed the proposal to permit abortion "wrong and immoral" while the bishop of the Guadalajara-Siguenza diocese accused the government of "seeking to become the official assassin of thousands of Spaniards." other groups opposed the restricting clauses in the Socialist bill. More than 100 doctors and health officials belonging to the minority Communist Party issued a statement calling for abortion on demand within the first three months of pregnancy. The government's proposal was also criticized by feminist groups.

Under the terms of the proposed legislation, which a government spokesman said will go before the parliament this week, abortion will be permitted at any stage in the pregnancy when the mother's life is in danger, up to the 22nd week when two health department officials testify that the fetus is severely physically or mentally disabled and within the first three months in cases of rapes that have been officially reported to police.

A major objection contained in a statement issued today by a feminist group from the northeastern region of Catalonia was that women would be subjected to the "humiliation" of notifying police that they had been raped.

Under existing total bans on abortion, women who terminate their pregnancies, as well as people who carry out abortions, are liable to sentences of up to 12 years jail. Periodic court cases dealing with abortion have attracted increasing publicity and a noticeable shift in judicial opinion.

In mid-January a retired 77-year-old male nurse was sentenced by a Barcelona court to 37 years in jail, suspended because of his age, for seven counts of carrying out abortions. The court ruling, however, included an unprecedented provision that called for an overhaul of the penal code to reflect changing attitudes about abortion.

The bans have in practice resulted in wide-scale back-street abortions, particularly among poor women. Backers of legalized abortion say deaths resulting from such practices in Spain could top 100 annually. The abortion problem, it is said, is aggravated by the absence of state-run family planning clinics.

At the other end of the social scale, Spanish press reports say that an estimated 20,000 wealthier women travel from Spain to London each year to terminate their pregnancies.

Despite such practices and the indications of new opinions among judges, the opposition to abortion in Spain is formidable. The fact that the government proposed lifting the ban on abortion only in restricted circumstances indicates how controversial the issue is.

The anti-abortion lobby, spearheaded by the church, received a considerable boost in November during a highly successful tour of Spain by Pope John Paul II. The pontiff, in a key act during his nine-day Spanish sojourn, rejected all forms of abortion in a spirited sermon preached during a mass open-air service in Madrid.

A spokesman for the Catholic Opus Dei association, which is well-entrenched in Spain, said that this religious grouping would promote publicity campaigns, public protests and use all leverage at its disposal to prevent the proposed legislation. The parliamentary opposition to the Socialists, the conservative Popular Alliance party, said it will test the legitimacy of the draft law before the constitutional court. The 1978 Spanish constitution refers directly to "the right to life."

A Socialist official said the battle over abortion would be "tough," but the government is confident that it can get the legislation through in its restricted framework. The official likened present opposition to the opposition to divorce which caused a minor storm when the bill was introduced two years ago. Divorce now raises little comment.

The official noted that if abortion is now practiced in Italy there is no reason to suppose that it will not be legalized in Spain.