The Archbishop of Canterbury has apologised to the gay and lesbian community for the "hurt and pain" caused by the church.

The Most Rev Justin Welby said it was a "constant source of deep sadness" that people were persecuted because of their sexuality as he spoke after a meeting of Anglican leaders.

Mr Welby said facing protesters, particularly those from Africa, was a reminder of the "pain and suffering of many LGBTI people around the world".

"For me it's a constant source of deep sadness, the number of people who are persecuted for their sexuality," he said.

"I don't have the right to speak for everyone. I wanted to take this opportunity...to say how sorry I am for the hurt and pain, in the past and present, the church has caused."

Mr Welby spoke after church leaders agreed to sanction the American branch of the Anglican Communion over its views on marriage and homosexuality.

A meeting of Anglican primates in Canterbury reached an agreement on measures against the US Episcopal Church, which a statement said had made a "fundamental departure from the faith and teaching" by endorsing gay marriage.

The agreement upheld a "traditional doctrine" of marriage as being between a man and a woman.

The summit aimed to avert a permanent schism in the Anglican Communion amid division dating back to the liberal church's consecration of Canon Gene Robinson, who is gay, as bishop of New Hampshire in 2003.

The primates' statement said: "The traditional doctrine of the church in view of the teaching of scripture, upholds marriage as between a man and a woman in faithful, life-long union. The majority of those gathered reaffirm this teaching."

Asked during a press conference if the church's position made it look outdated Mr Welby admitted that it did in some parts of the world, but not in others.

He said: "It makes us look out of line in the US and UK, yes, but not in many other parts of the world, no. We are a global church and that means that there are different views in different places."

The mistreatment of gay people in some countries, especially those where homosexuality is criminalised, remains a "major concern", Mr Welby added.

Asked about steps the church would take to continue to lobby against the attitudes in these countries he said: "We are not a centralised church which orders people what to do and how much time to spend on doing it.

"I spend an extensive amount of time on this subject both with fellow primates and elsewhere. It is a major concern."

Mr Welby insisted the US Episcopal Church had not been sanctioned but had faced "consequences", and the decision was supported by the "overwhelming majority" of Anglican primates.

It has been banned from taking part in ecumenical and interfaith bodies, internal committees or votes on doctrine or polity for a period of three years.

The Anglican leaders said there was a "unanimous desire to walk together" and the divisions had caused "deep pain throughout our Communion".

The decision was met with dismay by some including senior Labour MP and former Anglican minister Chris Bryant, who is gay.

He tweeted: "I've finally given up on Anglican church today after its love-empty decision on sexuality. One day it will seem wrong as supporting slavery."

The summit itself was tumultuous, as the Archbishop of Uganda walked out after failing to get a resolution passed for the Episcopal Church and the Anglican Church of Canada to withdraw from Communion activities.

Stanley Ntagali said the churches should be excluded "until they repented of their decisions that have torn the fabric of the Anglican Communion at its deepest level".

Mr Welby has been asked to lead a task group "with the intention of restoration of relationship, the rebuilding of mutual trust, healing the legacy of hurt, recognising the extent of our commonality and exploring our deep differences".

The head of the Episcopalian church said the decisions reached by the Primates' conference would bring "great pain" to gay and lesbian Anglicans and he believed "the exclusion or segregation of anybody is not the way of God".

Presiding Bishop Michael Curry said: "That is a matter of God-given human dignity. All people are God's children and that we're all created equal in God's eyes. Those who are baptised followers of Jesus - whether they are straight gay, lesbian, bisexual or transgendered - if they're committed to following the way of Jesus, they should have equal access to all of the services and sacraments in the life of the church.

Speaking to BBC Radio 4's World Tonight he compared the experience of the gay and lesbian community to that of the African-American community and said "even after emancipation there were those who were excluded and segregated".

He added: "This decision is going to bring great pain for people in our church who really believe that this is supposed to be a house of prayer for all people."

The leader of the US branch of the Anglican church then defended its decision to allow same-sex couples to be married in the church, but he acknowledged it was controversial.

He said: "We've made room and space for those who disagree. Even in our own church everyone doesn't agree with this decision and so we've made room and space for those who disagree with us on the question of marriage so that no bishop or priest will ever be compelled to act against their conscience and required to marry.

"It's a price worth paying for the sake of our standing for what we believe to be true.

"We remain full members of the Anglican communion."