Media playback is unsupported on your device Media caption The #SaveRahaf campaign went viral after Rahaf started tweeting about her plight for asylum

A Saudi woman who fled her family and became stranded at Bangkok's main airport is flying to Canada after being granted asylum status.

Rahaf Mohammed al-Qunun, 18, had been trying to reach Australia via Bangkok, but was initially told to return to Kuwait, where her family were waiting.

She refused to fly back and barricaded herself into her airport hotel room, attracting international attention.

She said she had renounced Islam, which is punishable by death in Saudi Arabia.

The UN's refugee agency has said it considers her to be a legitimate refugee.

Refugee status is normally granted by governments, but the UNHCR can grant it where states are "unable or unwilling to do so", according to its website.

Canadian Prime Minister Justin Trudeau told reporters: "Canada has been unequivocal that we will always stand up for human rights and women's rights around the world. When the UN made a request of us that we grant Ms al-Qunun asylum, we accepted."

Canada has previously angered Saudi Arabia after calling for the release of detained women's rights activists in the country - prompting Riyadh to expel Canada's ambassador and freeze all new trade.

The UNHCR has welcomed Canada's decision to resettle Ms Qunun.

The UN High Commissioner for Refugees, Filippo Grandi, said: "[Her] plight has captured the world's attention over the past few days, providing a glimpse into the precarious situation of millions of refugees worldwide.

"Refugee protection today is often under threat and cannot always be assured, but in this instance international refugee law and overriding values of humanity have prevailed."

What happened to Rahaf Mohammed al-Qunun?

She was on a trip to Kuwait with her family, when she fled on a flight to Bangkok.

She said she intended to take a connecting flight to Australia - and had an Australian visa - but that her passport was seized by a Saudi diplomat when he met her coming off the flight at Suvarnabhumi airport, leaving her stranded.

A Saudi envoy in Bangkok denied any official Saudi involvement in Ms Qunun's detention.

Thai officials initially described her case as a "family problem" and said she would be repatriated back to Kuwait the next day.

However, Ms Qunun sent a series of tweets pleading for help from her airport hotel room, and her case was picked up by Human Rights Watch and journalists.

A number of countries, including Australia, have considered her case for asylum.

'Threats to her life'

Analysis by Jonathan Head, BBC south east Asia correspondent

Image copyright UNHCR Image caption Ms Qunun, seen here at a UN building before leaving Bangkok, is en route to Toronto via Seoul

After days of speculation that she would move to Australia, Rahaf al-Qunun found herself on a flight in the opposite direction, to Canada. She was seen briefly, being escorted to the departure gate by UN officials.

As her plane took off Police General Surachate Hakparn, the immigration chief whose change of heart on Monday allowed her temporary asylum in Thailand, told journalists she had left the country cheerful and grateful to those who looked after her here.

Her father and brother, he said, who had come on what turned out to be a futile visit to try to persuade her to return to Saudi Arabia with them, would be leaving Thailand shortly after her.

It is only two days since the Australian government announced that it had been approached to take Ms Qunun, and that it would treat her request sympathetically. The UN usually approaches only one country at a time to seek asylum.

It is not clear why the Australian option fell through, and the UN switched to Canada. It might be that Australia's tough line towards refugees, and the insistence of its Home Affairs Minister Peter Dutton that she would get no special treatment, threatened to slow down the processing of her application.

The UN was concerned about her safety, following online threats to her life, and Canada may have been able to process her resettlement more quickly.

Why did she flee?

Renunciation of Islam is punishable by death in Saudi Arabia.

Under Saudi Arabia's "male guardianship system", a Saudi woman is required to obtain a male relative's approval to apply for a passport, travel outside the country, study abroad on a government scholarship, get married, leave prison, or even exit a shelter for abuse victims.

Ms Qunun told the BBC: "I shared my story and my pictures on social media and my father is so angry because I did this... I can't study and work in my country, so I want to be free and study and work as I want."

She also said she was afraid her family would kill her.

Separately, she told AFP she had suffered physical and psychological abuse from her family, including being locked in her room for six months for cutting her hair.

A spokesperson for her family told the BBC that they did not wish to comment and all they cared about was the young woman's safety.

On Friday, Ms Qunun wrote on Twitter that she had "some good news and some bad news", before deleting her account. Her friends said she had received death threats online.

Has anything like this happened before?

Yes. Ms Qunun's case echoes that of another Saudi woman who was in transit to Australia in April 2017.

Dina Ali Lasloom, 24, was en route from Kuwait via the Philippines but was taken back to Saudi Arabia from Manila airport by her family.

She used a Canadian tourist's phone to send a message, a video of which was posted to Twitter, saying her family would kill her. Her fate on arriving back in Saudi Arabia remains unknown.

'Rahaf is an inspiration'

'Sara', a Saudi woman, spoke to BBC OS on the World Service on Wednesday

Rahaf is an inspiration. But she's not the first one who did this and definitely not the last one.

What we are going through is awful. We think about this every day because us women here do not know what it feels like to go out. We don't know what freedom tastes like.

Dad keeps my passport with him all the time, we go to hotels and he puts it next to him when he sleeps.

Unfortunately it's not a revolution. Every girl that is tweeting about this, it's either that she has already escaped or she's using a fake account like me. Some people tweeted me or DMed me to tell me to use my real account, for me to be brave.

We do not want the guardianship any more. I want to go out of the house and drink coffee from Starbucks. I don't have to take my whole family. This is just way too harsh on us.

Living this life is exhausting.