The main political parties supported a bill establishing jail sentences of six to 30 years for women who terminate their pregnancies and doctors who perform the procedure.

The proposal was fast-tracked through parliament in the run-up to a presidential election next month, prompting accusations that it was an opportunistic vote-grabbing ploy.

The bill, if signed into law by President Enrique Bolaños, will overturn a 130-year-old policy permitting abortions in exceptional cases and put Nicaragua among several countries, mostly in Africa and the Middle East, with total bans. Latin America seemed to be going the other way, with Mexico, Colombia and Chile signalling possible moves to loosen abortion laws.

Human rights groups and medical associations said the decision would endanger women's lives and criminalise doctors who tried to save their patients. A few politicians have also voiced opposition, saying it was "mad" to make such an important decision in the heat of an election.

However, leaders of the ruling conservative Liberal Alliance and the opposition leftwing Sandinistas, which control all but one of parliament's 92 seats, voted in favour. Permitting abortions in exceptional cases, they said, gave pregnant women and sympathetic doctors a loophole by citing risk to health.

Rafael Cabrera, an obstetrician and leader of the Yes to Life movement, told journalists that medical science advances meant a foetus could be brought to the point of viability without endangering the mother's life. "We don't believe a child should be destroyed under the pretext that a woman might die," he said.

The church, a powerful force since 85% of the population of 6 million is Catholic, drove the campaign. Posters, billboards and pamphlets urged people to vote against pro-abortion candidates, a message echoed at a recent 200,000-strong rally in the capital Managua. The bill drew heavily on a text drafted by the Nicaraguan Catholic Bishops Conference. A pro-choice march drew just a few hundred people.

Daniel Ortega, the Sandinista leader and former president who has a strong chance of getting his job back, has backed the ban. Last year he was married by a Catholic cardinal and in recent months has quoted the Pope and been photographed attending Mass.

Critics, including some within the Sandinistas, said the 60-year-old former revolutionary had betrayed the movement's tradition of feminism and liberalism to try to clinch victory in the first round of the presidential election on November 5. Of the four leading candidates, Edmundo Jarquín, leader of a dissident Sandinista faction, was the only one to oppose the bill.

In the past three years, only 24 legal abortions have been performed, including one in 2004 carried out on a nine-year-old rape victim, but it is an open secret that many well-off families send female relatives to Cuba for the procedure. A third of new mothers are aged 16 or younger and in opinion polls women cite domestic abuse as one of their biggest problems. Tens of thousands of pregnant women are estimated to have illegal abortions in Nicaragua every year.

An open letter from medical workers this week pleaded with legislators to reject the bill. Efrain Toruno, president of the Nicaraguan Society of Gynaecology and Obstetrics, told a news conference that his colleagues would be afraid to do anything if a woman with vaginal bleeding arrived at hospital. "If we treat her we could be prosecuted, and if we don't we could also be prosecuted."