July 25th is the feast day of Saint James, Spain's patron saint. So why wasn't the new Spanish prime minister, José Luis Rodriguez Zapatero, in a more celebratory mood on this auspicious day?

Zapatero had accompanied Spain's King Juan Carlos for the special Jacobean mass in the cathedral of Santiago de Compostela. According to Catholic tradition, Santiago de Compostela is the resting place of the Apostle James, also called the Matamoros because his spectral form was apparently seen in battles against the Moors, encouraging the Christians to smite the infidel ever harder.

We don't know whether the new socialist premier sees an unpleasant irony in paying homage to an infidel-smiting, ass-kicking patron saint so soon after the atrocities of the 11 March train bombings, and his government's decision to withdraw Spanish troops from Iraq. But tradition is tradition, and whether he liked it or not, Zapatero had to go to mass that day.

Even if he'd been stirred by the grandeur of the cathedral, mediaeval Europe's most hallowed place of pilgrimage, such feelings would not have lasted long. For the Archbishop of Compostela used this most public occasion to preach a sermon launching an attack on Zapatero's newly unveiled social policies, in particular plans to allow gay couples to marry.

The TV cameras recorded every word of the sermon, including Zapatero's reaction – as pissed off as a prime minister can be in public.

The incident represented yet another escalation in the church-state war that began when Zapatero won his surprise general election victory on 14 March. The last conservative government of José Maria Aznar had always been much more the Church's cup of tea in terms of 'family values' and the socialists' surprise win had plunged the Church into consternation.

First, there was the issue of the conservatives' education reforms, which had scheduled more hours of religious studies for the curriculum. The Spanish church was cock-a-hoop when Aznar introduced the legislation last year, and had almost certainly used its close links with senior ministers to put its wishes across. The bishops, along with most other people, fully expected Aznar's party to win its third term in March, ready to implement the reforms for this September.

But, as we all know, Aznar spectacularly lost the election in the wake of the Madrid bombings. And one of Zapatero's first decisions was to suspend the education reforms. A new law is being drafted which will, it is widely predicted, be far lighter on religion.

That may have rankled the Church – but nothing like as ferociously as the gay marriage issue which has since erupted.

Hostilities intensified at the end of June, when the government introduced a bill into parliament that will open the way for gay marriage by next year, offering a raft of measures to give gay couples legal and financial parity with married couples.

On 20 July, an official document published by the bishops called on Catholic MPs to reject the proposed legislation. It hammered home the Church's teaching that marriage should only take place between a man and a woman, and included this rather baroque (and, some would argue, rather offensive) conceit: "Making false currency devalues the true currency and endangers the whole economic system."

Given this background, perhaps Zapatero should not have been all that surprised that the Church used the feast day of Saint James, a few days later, to make its point. And the Archbishop of Compostela, Julián Barrio, did not mince his words. To allow gays to marry, he told worshippers, would make society "vulnerable to interests that do not serve the common good".

In zoomed the TV cameras on Zapatero's face. Never has a facial expression asked more clearly: "Who will rid me of this turbulent priest?"

Archbishop Barrio, in tune with the bishops' declaration a few days before, summoned a defence that is increasingly being cited these days: that the bishops have a right and duty to criticise social policy. The Church has been emboldened in this by the Pope himself, who had given Zapatero a good ticking-off on the gay issue in their first face-to-ace meeting in early June.

But it is not merely a question of the Church sounding off, either in the pulpit or newspapers, which, of course, it has every right to do. What exercises Spanish secularists is the tactic whereby the Church calls on observing Catholic MPs to vote down legislation it doesn't like.

This is what Gaspar Llamazares, the leader of Spain's minority left-wing party, Izquierda Unida, means when he accuses the Church of 'delegitimising' parliament. The seminaries may be growing emptier by the year, but the Church remains a powerful institution in Spain. It has many allies among the conservatives, and has used its lobbying influence to get policy through in the past: the now-suspended educational reform is a good example.

But even if its instincts were never democratic, the reality for the Church now is that it is suddenly very isolated. Its conservative allies are languishing in opposition, beset by mounting allegations that they tried to manipulate the aftermath of the Madrid bombings.

Indeed, some of those same allies are even moderating their stance on gay rights. To the surprise of all, some conservative deputies even voiced approval for the notion of gay marriages during the parliamentary debate in June.

Even more worrying for the church is that the flock are not being as biddable as it would like. A poll published in July revealed that while nearly 80 per cent of Spaniards regard themselves as Catholics, over 65 per cent approve of the right of gay people to marry. The average Spanish Catholic's view of what constitutes Catholicism obviously diverges greatly from that of their clergy.

The poll reflects a wider social trend in Spain: that while most people baptize their children, and join in the festivals of the Catholic year that are so much part of Spanish family life, the allegiance is cultural. Very few people attend mass. The social pronouncements of the bishops are often mocked in the mainstream press, while remaining a matter of total indifference to most ordinary Spaniards.

All this goes some way to explain the outpourings of paranoia by the Spanish Church, which have intensified since the general election in March: that the left is out to get them; that they are the victims of a hate campaign by secularists. Their stance is a defiant one. They will not, as one ultraconservative bishop put it recently when pronouncing on gays, "succumb to the threats of the dominant culture".

To some extent they are right to feel under pressure, especially with the left in power. The Church is regarded by Spanish left wingers as the source of both the educational and legal expertise and the reactionary doctrine that sustained Franco.

This can often be an over-simplistic view, as there were liberal elements in the Church during the dictatorship; and it is certainly true that some Spanish left wingers are simply intolerant to any religious sentiment. But any moderate secularist, including many Catholics, can only look with dismay at the ultraconservative bent of the Spanish Church and its political allies on the right.

New Humanist readers may be particularly interested to know that under Aznar's proposed education reforms described earlier in this article, pupils would have taken more hours of religious studies than biology in their whole secondary school career.

In a country with low standards of science teaching in secondary schools (which in turn has fed Spain's poor record on scientific research at universities) such an educational policy was madness. This, together with its fulminations on modernity and its intolerance towards homosexuals, strengthens the view that the Spanish Church still greatly fears science, reason, pluralism and open debate.

But there is one final issue which has recently become of as great a concern to the Church in Spain – something much more fundamental than education or homosexuality. It is looking increasingly likely that Zapatero and his little demons in the Socialist Workers' Party are going to review how much money they will give the Church in future.

Spain's 1976 Concordat with the Vatican allows Catholics to donate a proportion of their income tax to the Church. But it did not offer such a revenue stream to other faiths, even though Spain is, according to its constitution, 'aconfessional'.

Zapatero's government is now proposing to give other faith communities the chance to donate tithes through income tax. The Church does not have a problem with this – indeed, it welcomes it, partly because by being part of a new, pluralistic system, the Church will no longer be castigated for unfairly acquiring public funds.

But here is the rub: Back in July, the Social Affairs minister Jesús Caldera pointed out that although the Church receives 90 million euros through voluntary tithes, the public purse is still providing an additional 48 million euros annually to keep it going.

As the minister said in a statement as ominous as it was brief: "This situation should be revised."

Even before this development, the bishops had been getting wind in the press of the government's plans to cut back what it gives the Church. Only this can explain words from the ultraconservative archbishop of Toledo, Antonio Cañizares, who in July preached a sermon predicting that if gays received certain basic rights, cosmic disorder would ensue. The sermon was full of the usual cryptic and paranoid utterances: "They can't scare us by the threat that they can strip us of our belongings," fulminated the primate. "The Church knows how to live with being poor!"