Image caption Thirty of the 38 people killed by a gunman on a Tunisian beach were British

Tunisian security forces "wasted time" before responding to a massacre on a beach resort as 30 British tourists were shot dead, a UK coroner has heard.

In total, 38 people died in the hour-long gun attack near Sousse in June 2015.

But local units deliberately "slowed down" as Islamist gunman Seifeddine Rezgui opened fire, said the counsel to the inquest into the British deaths.

The attack was the deadliest on Britons since the 7 July 2005 London bombings.

A senior Foreign Office official also defended the government's decision not to raise the level of its terror alert in Tunisia following shootings at a museum in the capital city of Tunis four months earlier.

Survivors share their stories of terror on the beach

Who were the British victims?

What exactly happened on that day?

The hearing at London's Royal Courts of Justice - set to last for seven weeks - began with a minute's silence and the names of all the victims being read out.

Media playback is unsupported on your device Media caption Tunisia inquest shown police map of killer's spree

The 38 tourists who visited Tunisia for "relaxation and enjoyment" were "systematically" gunned down from around 11:30 local time on 26 June 2015, said Samantha Leek, counsel to the inquest.

She said the attack could have been stopped sooner, citing a Tunisian judge's report into failings by local security units.

Survivors' story: Alison and Baron

Media playback is unsupported on your device Media caption Tunisia survivor: 'This is it, we're going to die'

Alison and Baron Caine, who were on the beach when the attack began, told the BBC that they escaped the gunfire and barricaded themselves in their hotel room.

"We started hearing screams, people were running," Mrs Caine said. "It was like a complete warzone."

The couple heard a knock on their hotel room door and a man saying he had their key.

"We looked at each other and we just thought this is it, we're going to die."

A lone armed guard was on the beach when Rezgui opened fire. The gunman also threw a grenade and left the guard "seemingly unconscious".

A second armed guard on duty was patrolling the nearby sea in a speedboat. He attempted to shoot Rezgui but could not work his gun.

Nearby security forces "had an ability to put an end to the attack" before the police arrived, Ms Leek said, but they "deliberately and unjustifiably slowed down to delay their arrival at the hotel".

Meanwhile, witnesses telling of the man with the gun in the speedboat may have led to confusion over how many attackers there were, she added.

Image caption CCTV footage played to the inquest showed the killer as he entered the hotel

Rezgui was shot dead by police about an hour after the attack began.

The court hearing the inquest's opening day of evidence was filled with relatives and friends of the British dead, who were aged between 19 and 80.

Three people from Ireland, two Germans, one Russian, a Belgian and a Portuguese woman were also killed.

They were all holidaymakers staying in the popular resort of Port El Kantaoui, just north of Sousse.

Three generations of a family - a young man, his uncle and grandfather - were among them.

Stepped-up security

At the time of the shootings, official travel advice from the UK Foreign Office did not specifically advise holidaymakers against going to Tunisia.

Instead the advice available on its website stated "further attacks are possible", following the killing of 24 people at the Bardo National Museum in Tunis on 19 March 2015.

Jane Marriott, the Foreign Office's Middle East and North Africa director, told the inquest that the level of the terror alert relating to Tunisia had not been raised, with officials deciding "we should not discourage tourism to Tunisia".

The government did persuade Tunisian authorities to step up security in tourist areas, she said.

Ms Marriott said the UK was powerless to force Tunisia to improve its security, but "what we can and we do say is that we want to see an improvement in your security."

Image copyright PA Image caption Victims' relatives have been attending the hearing at the Royal Courts of Justice

Over the next seven weeks, the court will examine whether the UK government and travel firms failed in their responsibility to protect British tourists.

The coroner, Judge Nicholas Loraine-Smith, will look at travel advice issued for Tunisia by the Foreign Office, as well as the security put in place at the hotel by tour operator Thomson.

The inquest was shown CCTV footage of Rezgui as he was dropped off in a white van.

Photos of the Imperial Marhaba Hotel, including its beach where the attacks started, were also shown as evidence.

Live TV feeds of the proceedings were also shown in courts in Cardiff and Stirling for survivors and relatives to watch.

'Mastermind' on the run

The government has applied for some details to be kept private over national security concerns.

The Islamic State militant group said it was behind the attack by the Tunisian student.

The BBC's Panorama programme this month reported that the suspected "mastermind" behind the shootings is believed to be on the run in Libya.

Chamseddine al-Sandi recruited and directed Rezgui, according to documents obtained by Panorama.

And confessions from suspects arrested by Tunisian police state that al-Sandi ran a militant cell responsible for both shootings - the attacks at Sousse and at the Bardo National Museum.