A UK teacher has been released and handed over to British officials in Sudan after being jailed for letting her class name a teddy bear Muhammad.
Gillian Gibbons, 54, from Liverpool, was freed after eight days in custody. She had been given a 15-day jail term.
Sudan's President Omar al-Bashir pardoned her after talks with two British Muslim peers.
In a statement, Mrs Gibbons apologised for "any distress". Prime Minister Gordon Brown said he was "delighted".
Mother-of-two Mrs Gibbons has been released into the care of the British embassy in Khartoum, but her exact location has not been disclosed.
She was released four days after receiving a 15-day sentence for insulting religion.
Following her release, Foreign Secretary David Miliband said the teacher was "a little overwhelmed" at the attention her case had attracted, but was in "remarkably good spirits" and "elated to be back on her way home".
Mr Miliband also hailed the "team effort" which led to Mrs Gibbons's release, praising diplomatic staff and saying that the intervention of Baroness Warsi and Lord Ahmed had been "an important contribution".
Earlier, a demonstration of about 30 or 40 people was held outside the embassy in Khartoum, with banners protesting about the decision to release her.
Mrs Gibbons was arrested on 25 November and jailed on 29 November after allowing her pupils to name a teddy bear Muhammad.
She was arrested after another member of staff at Unity High School complained to the Ministry of Education about the incident in September.
The press office of President al-Bashir announced that he had pardoned Mrs Gibbons following his meeting with Baroness Warsi and Lord Ahmed, and that she had been "released after their mediation".
TEDDY ROW TEACHER TIMELINE
Sept: Gillian Gibbons' class votes to name a teddy bear Muhammad
25 Nov: She is arrested for allegedly insulting Islam's Prophet
27 Nov: Gordon Brown says efforts are being made to release her
28 Nov: Mrs Gibbons is charged with insulting religion and inciting hatred
29 Nov: A Sudanese court finds her guilty of insulting Islam and sentences her to 15 days in prison and deportation
30 Nov: Angry protesters in Khartoum demand a harsher sentence
1 Dec: Two British Muslim peers press Sudanese officials to pardon her
3 Dec: Mrs Gibbons is pardoned by Sudan's president and freed from prison
In a statement read out by Baroness Warsi, Mrs Gibbons said: "I have great respect for the Islamic religion and would not knowingly offend anyone and I am sorry if I caused any distress.
"I am looking forward to seeing my family and friends but I am very sorry that I will be unable to return to Sudan and work in Unity High School as the teacher of 2X."
Lord Ahmed thanked the president for granting the pardon and said both he and Baroness Warsi were proud to have been able to help Mrs Gibbons.
"This is a case which is unfortunate, unintentional, innocent misunderstanding, and as British Muslim parliamentarians we, Baroness Warsi and myself, we feel proud that we've been able to secure Gillian Gibbons's release."
Speaking later, Baroness Warsi said that when she and Lord Ahmed had visited Mrs Gibbons in custody, all three had made "lots of Yorkshire jokes". All three were brought up in the county.
Asked how she and Lord Ahmed had helped to win freedom for Mrs Gibbons, Baroness Warsi said: "We played very different roles but complementary roles with different negotiation skills which had to be used."
Mr Brown said it was "completely wrong" that Mrs Gibbons had been detained, and described her imprisonment as "completely unacceptable".
The peers met Sudanese President Omar al-Bashir
He said: "Through the course of Mrs Gibbons's detention I was glad to see Muslim groups across the UK express strong support for her case.
"I applaud the particular efforts of Lord Ahmed and Baroness Warsi in securing her freedom. I am also grateful to our officials for all their work behind the scenes."
Speaking to reporters outside his home in Liverpool, Mrs Gibbons's son John said he was "very pleased".
He said: "I'd like to thank the government for all they have done, the hard work behind the scenes, especially the two peers who went out there.
"Everyone's been really great. Obviously it's a great feeling today, we're very pleased, we have been under a lot of pressure."
He said his mother would be "very pleased, although quite embarrassed to be on the news permanently".
Dr Khalid al-Mubarak, of the Sudanese embassy in London, said he hoped the affair would not damage relations between Sudan and the UK.
"I think this is the correct resolution - pardoned and released early," he told BBC News.
"The word pardoned also means that the original mistake has been - not forgotten - but behind us now."
Ibrahim Mogra from the Muslim Council of Britain told BBC News 24 that the whole saga had been very damaging for the image of the Muslim faith.
"Each time we have stories like these, that distort what Islam stands for or misrepresents what the compassion of Muslim law stands for, then we have repercussions and people begin to feel that Islam has no place in modern society...
"I have not come across one single Muslim in our country who has supported what has happened.''
President Omar al-Bashir had been under pressure from Sudanese hardliners to ensure Mrs Gibbons served her full sentence.
There had been a protest, and calls for a retrial and for the sentence to be increased.
BBC Islamic affairs analyst Roger Hardy said the row over Mrs Gibbons had strained relations between Britain and Sudan - and, beyond that, between the West and Islam.
And even if intervention by two prominent British Muslims had succeeded in limiting the damage, the fact remained that damage had been done, he added.