MADRID—Spain's government withdrew a bill that would have imposed some of Europe's strictest curbs on abortion, bowing to popular sentiment and dissent within the ruling conservative Popular Party.

The decision Tuesday by Prime Minister Mariano Rajoy on one of the most divisive social issues in this largely Roman Catholic country prompted sharp protests from some of his party's core supporters. His justice minister, the bill's chief advocate, resigned.

Mr. Rajoy's party made the bill a campaign promise before sweeping to power in 2011, largely as a result of voter discontent over Spain's economic slump. The bill proposed allowing abortion only for women whose pregnancies result from rape or threaten them with serious health risks. Polls this year showed as many as 80% of Spaniards opposed the bill.

With municipal and national elections looming next year, Mr. Rajoy appeared willing to risk alienating social conservatives and Catholic Church leaders in order to stem a broader erosion of support. He said the government had done all it could to achieve a multiparty consensus for the change but had failed. The bill, adopted by his cabinet in December, won't be submitted to parliament, his office said.

"We can't have a law that will be changed when another government comes in," he said.