The British woman stabbed to death at a backpackers’ hostel in Australia by a knife-wielding attacker shouting “Allahu akbar” was identified Wednesday as a 21-year-old who was trekking around the country.

Mia Ayliffe-Chung was killed by a 29-year-old French national who also injured two men during the Tuesday night attack before a group of up to 30 witnesses at Shelley’s Backpackers in the Home Hill area of north Queensland at about 11:15 p.m., police said.

The unidentified suspect — who was in Australia on a valid temporary tourist visa — was quickly arrested and appeared to have acted alone, but cops are looking into whether he was linked to any extremist groups such as the Islamic State.

Police said they are not ruling out any motive “whether they be criminal or political,” said Queensland Police Service Deputy Commissioner Steve Gollschewski.

“We could be dealing with a pure criminal act or something related to mental health or drug issues,” said Gollschewski. “It is alleged that the suspect used the phrase ‘Allahu akbar’ during the attack and when arrested by police.”

Ayliffe-Chung — described by friends as “gorgeous” — studied psychology at Chesterfield College in North East Derbyshire, England, before moving to Surfers Paradise on Australia’s Gold Coast.

She had worked as a nightclub waitress in the area before journeying north just days ago to work on a farm in a rural area so she could extend her working holiday visa, Australian and British media reported.

Last week Ayliffe-Chung posted to her Facebook page — where she documented her journey — “Day 4 done. Just 85 left! Skills achieved; the ability to tell the difference between a rock and a clump of mud and throwing stones really far. The sun is too hot. Stupid Australia.”

Friends as well as strangers took to Ayliffe-Chung’s Facebook page to mourn her.

“R.I.P. Mia..You were such a joyful..beautiful girl. I also say WHYYY…” Facebook user Sheila Truesdell commented on her page.

Kyle Godwin wrote: “We really do live in a cruel world. The only good thing to come from this is that heaven really truly has gained an amazing and beautiful soul. I love you more then anything in this world beautiful.”

Amy Browne, a 19-year-old Gold Coast resident who worked as a bartender at the Bedroom Lounge Bar where Ayliffe-Chung was a waitress, told the Press Association, “Mia was honestly the most bubbliest and most caring girl I knew.”

The suspect was hospitalized with minor injuries. Charges against him were pending.

Police found Ayliffe-Chung dead at the scene.

A 30-year-old British national identified by British media as Tom Jackson who was injured during the attack was continuing to fight for his life. A 46-year-old man was also injured with non-life-threatening injuries. The attacker also knifed a dog to death.

Queensland police called the attack “a senseless act of violence.”

Australia, a US ally, has been on heightened alert for attacks by home-grown Islamist radicals since 2014 and authorities say they have thwarted a number of plots by Islamic extremists.

With Post wires