WHEN people turned up for mass a week past Saturday evening at Our Lady of the Waves Church in Dunbar they knew that it would be conducted by Cardinal Keith O'Brien.

What they did not suspect, however, was that it would be his last as Britain's most senior Catholic.

The Cardinal, who was due to retire next month on his 75th birthday, had previously intimated that he was keen to move from Edinburgh to the East Lothian seaside town where he is a familiar figure.

Herbert Coutts, vice-chair of the church's parish council, told the local paper: "The intention was that he would do masses in Dunbar as he could, so to speak, because there is a shortage of priests and our priest covers both Dunbar and North Berwick, so that would be of assistance to him."

That won't now happen. Hours after telling one member of the congregation to "keep carrying the flag" for the Catholic Church, O'Brien was accused by three priests and one former priest, who is now married, of "inappropriate behaviour".

O'Brien would have known this was in the pipeline as he preached at Our Lady of the Waves. His four accusers, none of whom has yet been identified, circumvented the hierarchy of the Scottish Catholic church, and took their grievances directly to nuncio Antonio Mennini, the Vatican's ambassador to Britain. The result was O'Brien's resignation.

According to The Observer, which ran the initial story, the four men made allegations dating back to 1980, when one of them was a 20-year-old seminarian at St Andrew's College, Dryrange, where O'Brien was his "spiritual director".

The three other priests also submitted statements insisting they were subjected to inappropriate contact and unwanted behaviour. Mennini replied by email thanking them for their courage.

A spokesman for the cardinal initially said O'Brien would "contest" the allegations until that was overtaken by today's dramatic admission of inappropriate sexual conduct.

Last week, senior figures for the Church expressed their shock at the first report. It was an understandable reaction. For, only a few days before the dropping of the bombshell, O'Brien had spoken enthusiastically of his anticipated participation in the conclave to choose a successor to Pope Benedict XVI who earlier this month stunned the world by announcing his intention to step aside.

O'Brien was proud of the fact that he would be the sole British representative in Rome, the culmination of a career in the priesthood spanning more than fifty years. Apparently unaware of the tornado heading in his direction, he spoke of the need for a younger pontiff, perhaps one recruited from the developing world. "I would be open to a Pope from anywhere if I thought he was the right man," he said, "whether it was Europe or Asia or Africa or wherever."

But he also took the opportunity to suggest that it was perhaps an opportune moment for the church to rethink its position on celibacy.

"In my time," he said, "there was no choice and you didn't really consider it too much, it was part of being a priest. When I was a young boy, the priest didn't get married and that was that.

"I would be very happy if others had the opportunity of considering whether or not they could or should get married. It is a free world and I realise that many priests have found it very difficult to cope with celibacy as they lived out their priesthood and felt the need of a companion, of a woman, to whom they could get married and raise a family of their own."

Such remarks were enough to shock Catholics and non-Catholics alike. O'Brien is no liberal and is known as a forthright and intemperate critic of reform. For his views on gay marriage and homosexuality, for example, he was name "bigot of the year" by Stonewall, the gay rights charity.

Last Sunday morning, when as one prominent Catholic observed "all hell broke loose", O'Brien was scheduled to preside over mass at Edinburgh's St Mary's Cathedral. In the event, he decided against exposing himself to the media and remained behind the walls of his Morningside mansion.

In his stead was Bishop Stephen Robson, auxiliary bishop of the Archdiocese of St Andrews and Edinburgh who confessed that he, too, was "gobsmacked" by the allegations.

Asking that the congregation remember O'Brien in their prayers, he added: "As always at times such as this, we cannot but be saddened by the events of the past 24 hours. The bark of Peter ... is suffering from the effects of many storms at this present time, but the Lord is always with us, to help us weather them and to calm down."

Doubtless O'Brien was receiving similar advice from his advisers. But this was a furore outwith their control. In Rome, at the Vatican, officials were already having to cope with a nigh unprecedented situation, the resignation of a living pope. The last thing they needed was an attention-diverting scandal in a country on the outer fringes of catholicism.

Years of child abuse accusations around the globe have taken their toll on the Catholic Church and damaged it grievously. The blind trust on which it could formerly depend is no more. To regain this it must regroup, reform and clear out those who did nothing when they knew of abusive priests or were abusers themselves.

That a cardinal accused of "inappropriate behaviour" should be allowed to attend the conclave at which a new pope will be elected was therefore deemed unconscionable. The axe fell swiftly and cleanly. Last Monday, Osservatore Romano, the Vatican's official newspaper, announced that the outgoing Pope had accepted O'Brien's offer to stand down.

In his valedictory letter, O'Brien wrote: "The Holy Father has now decided that my resignation with take effect today, February 25, 2013, and that he will appoint an Apostolic Administrator to govern the Archdiocese in my place until my successor as Archbishop is found."

And he added: "I do not wish media attention in Rome to be focused on me – but rather on Pope Benedict XVI and on his successor.

"However, I will pray with them [the cardinals who will appoint the next pope] and for them, that enlightened by the Holy Spirit, they will make the correct choice for the future good of the Church.

"May God who has blessed me so often in my ministry continue to bless me and help me in the years which remain to me on earth and may he shower his blessings on all the peoples of Scotland, especially those I was privileged to serve in a special way in the Archdiocese of Saint Andrews and Edinburgh."

But the floral nature of the language could not hide the confusion, hurt and uncertainty consuming the church and its celebrants in Scotland. As Bill Heaney, formerly a special adviser on media matters to Henry McLeish, pointed out, there was, until the allegations, a possibility, albeit remote, that O'Brien could be the next pope.

"Scoff if you will," he wrote, "the Scottish faithful told sceptics, but that the very fact Cardinal O'Brien was going to be in the Vatican taking part in the election meant he could be the next pope. He was in it and could very well win it, they said. The foundations of their joy trembled ever so slightly, however, when it was revealed, that four priests, had accused Cardinal O'Brien of 'inappropriate behaviour' towards them."

But who are these four priests? That was what Catholic observers wanted to know, sceptical of their reasons for anonymity. Why had they come forward now?

There was, noted another Catholic commentator, "the whiff of payback" about their accusations. Another wrote: "Questions are also being raised in the parishes about the timing of the alleged victims' claims."

Historian Tom Devine wrote that his first reaction to O'Brien's resignation was one of "personal sadness" and "human concern for the cardinal; his terrible suffering at this time can only be imagined".

The sympathies of First Minister Alex Salmond were also with the cardinal. "It would be a great pity if a lifetime of positive work was lost from comment in the circumstances of his resignation," he said.

The plethora of positive comment was not echoed by many gay people in Scotland. One told the Sunday Herald: "I punched the air with joy." Like many in the gay community, he'd been angered by the tenor of the cardinal's comments on homosexuality and gay marriage.

As the week wore on, the rumours increased and the air of denial grew thicker. No-one inside the Catholic Church in Scotland seemed eager to speak. On Friday, however, reports of a fifth allegation against O'Brien emerged which, it was claimed, was lodged with the Vatican last October and which had prompted the four other priests to come forward.

The Tablet, the influential international Catholic newspaper, made clear to its readers where it stood: "When Cardinal Keith O'Brien called gay marriage a 'grotesque subversion' and 'madness' it attracted widespread censure. No wonder the accusations of inappropriate behaviour as a younger man – strenuously denied – were so damning. If true, it made him look a hypocrite. For the church this was a public-relations disaster.

"There is no more mileage in this issue for the Catholic Church, and the sensible course would be to put it on the back burner with the heat turned low – to make peace with the gay world and move on.

"Technically, yes, homosexuality is against the rules – but so is contraception; so is living together before marriage; so are lots of things people do in private. As the late Archbishop Worlock once said of contraception, these issues are 'not the acid test of Christianity'."