Media playback is unsupported on your device Media caption The BBC's Daniela Relph reports on the cardinal's resignation

Britain's most senior Roman Catholic cleric, Cardinal Keith O'Brien, is stepping down as leader of the Scottish Catholic Church.

He had been accused of inappropriate behaviour towards priests dating back to the 1980s - claims he contests.

Cardinal O'Brien, the Archbishop of St Andrews and Edinburgh, apologised to "all whom I have offended" for "any failures" during his ministry.

He will not take part in electing a new pope, leaving Britain unrepresented.

Analysis The resignation of Britain's most senior Roman Catholic cleric in the wake of allegations of improper behaviour creates a crisis for the Church in Scotland, and represents a heavy blow to the wider Church as it battles to shore up its reputation ahead of the papal election or "conclave". The conclave is already expected to be difficult in the circumstances created by Pope Benedict's unprecedented resignation. The Vatican is also struggling to deal with reports of internal corruption and mismanagement. Cardinal O'Brien's resignation is also a personal tragedy for himself. In resigning his post at the head of the Scottish Catholic Church, Cardinal O'Brien blights the end of an illustrious career only a few weeks before he was due to retire. Cardinal O'Brien will be remembered in particular as a forthright defender - occasionally in outspoken and colourful terms - of Catholic teaching on abortion, euthanasia and homosexuality.

The cardinal said in a statement: "I have valued the opportunity of serving the people of Scotland and overseas in various ways since becoming a priest.

"Looking back over my years of ministry: For any good I have been able to do, I thank God. For any failures, I apologise to all whom I have offended."

He remains a cardinal and would be entitled to join the conclave selecting the new Pope after Benedict XVI announced on 11 February that he would resign - but said he would not go.

"I do not wish media attention in Rome to be focused on me - but rather on Pope Benedict XVI and on his successor," he said.

"However, I will pray with them and for them that, enlightened by the Holy Spirit, they will make the correct choice for the future good of the Church."

The Vatican confirmed the cardinal has stepped down from his post.

Although the announcement has only just been made public, the Scottish Catholic Media Office said Pope Benedict had accepted the cardinal's resignation on 18 February.

Allegations made

The allegations against Cardinal O'Brien emerged in a report in the Observer newspaper on Sunday.

It said three priests and one former priest, from the diocese of St Andrews and Edinburgh, complained to the Pope's representative to Britain, nuncio Antonio Mennini, in the week before 11 February.

It said:

Media playback is unsupported on your device Media caption Father Thomas Rosica, Assistant Vatican Spokesman: "His resignation was already in progress"

The former priest claims Cardinal O'Brien made an inappropriate approach to him in 1980, after night prayers, when he was a seminarian at St Andrew's College, Drygrange. The complainant says he resigned as a priest when Cardinal O'Brien was first made a bishop

A second statement from another complainant says he was living in a parish when he was visited by O'Brien, and inappropriate contact took place between them

A third complainant alleges dealing with what he describes as "unwanted behaviour" by the cardinal in the 1980s after some late-night drinking

And the fourth complainant claims the cardinal used night prayers as an excuse for inappropriate contact

A Scottish Catholic Media Office spokesman said a number of bishops' appointments and resignations were being accepted in the last days of the Pope's time in office.

He said Cardinal O'Brien was taking legal advice and contested the allegations against him, which were "anonymous and non specific".

In Rome, the BBC's world affairs correspondent James Robbins said for a long time the Vatican had been able to "bat away" some criticism of other cardinals who may have been involved in covering up allegations of sexual abuse.

Analysis Cardinal Keith O'Brien's grand residence in a smart Edinburgh suburb has been both bathed in sunlight and illuminated by flashbulbs today. The cameras have been recording the comings and goings of a number of visitors: priests, a housekeeper, and one well-wisher with a bouquet of flowers. The well-wisher, Thelma Houston, said she was a friend of Cardinal O'Brien's and described the events of the past two days as "extremely sad". He had been looking forward to his retirement in Dunbar, she said, but instead faced a "terrible drop" from "the pinnacle of his career". As the shadows grew and the sun dipped behind the tree-lined houses of the cardinal's neighbours, the auxiliary bishop of Edinburgh and St Andrews, Stephen Robson arrived. He did not stop to speak as he drove in through the gates. The cardinal himself is said to be "quite serene; carrying on as normal" but the church in Scotland, which he has led for a decade, is in shock. People have noted that today's statement by Cardinal O'Brien does not contain a denial of the accusations levelled against him but nonetheless there is still some support and sympathy for him within the church. The dominant mood though is one of shock and uncertainty as parishioners and clerics seek answers to questions about both the past conduct and future direction of the Roman Catholic clergy in Scotland. Profile: Cardinal Keith O'Brien

But these were more serious because they alleged Cardinal O'Brien was involved directly in improper behaviour towards other priests.

He added that there was also a sense of regret that Britain would have no voice in the conclave to choose Pope Benedict's successor.

Cardinal O'Brien has been known as a outspoken defender of Catholic teaching on abortion, euthanasia and homosexuality.

He was named Bigot of the Year last year by gay rights group Stonewall Scotland, after he said gay marriage was a "grotesque subversion of a universally accepted human right".

Catherine Deveney, who wrote the Observer piece, said the story was important because the cardinal had set a "moral blueprint" for the way other people should lead their lives.

She said the complainants were "men of integrity" who had "done a difficult thing and acted according to their conscience".

Scotland's First Minister Alex Salmond said: "It would be a great pity if a lifetime of positive work was lost from comment in the circumstances of his resignation.

"None of us know the outcome of the investigation into the claims made against him but I have found him to be a good man for his church and country."

Jack Valero, from Catholic Voices, a media lobby group that represents many Catholics in Britain, said it was the right move for the cardinal to resign.

"I am very happy that they have been taken seriously, that the nuncio - the Pope's representative in the UK - has written to the four people who have made the allegations to thank them for speaking out, and that the whole thing has been done so quickly. I think this shows a new spirit."

Colin MacFarlane, director of Stonewall Scotland, said he hoped there would be a full investigation.

And that the cardinal's successor should "show a little more Christian charity towards openly gay people than the cardinal did himself".

But Clifford Longley, a religious commentator and columnist for the Catholic newspaper The Tablet, said the cardinal's resignation was "the worst thing that could possibly have happened to the Church at this moment - to have another row like this when there already so many going on."

Cardinal O'Brien was due to retire when he turned 75 next month. His resignation statement said the Pope would appoint someone to govern the archdiocese in his place, until his successor was appointed.