Even by the high standards of duty and self-sacrifice expected of professional soldiers and police officers the world over, the courage of Lt Col Arnaud Beltrame was extraordinary.

By offering to swap places with hostages held by a terrorist gunman who had already killed three people and had declared his allegiance to Islamic State (Isis), the decorated officer would have known he was almost certainly walking to his death.

In the last three years attackers with Islamist sympathies have attacked – and in certain cases killed – French police, gendarmes and soldiers on more than 10 occasions. Armed with nothing but this knowledge, Beltrame strode across the car park of the SuperU store in Trèbes, a small town near Carcassonne, to confront Radouane Lakdim, a self-described “soldier of the caliphate”.

The Frenchman of Moroccan origin had carried out three separate attacks that day, culminating in a three-hour siege at the supermarket, where he killed a member of staff and a customer and took several hostages. Beltrame left his mobile telephone line open, enabling police and special forces outside the supermarket to hear what was going on. When they heard shots, they stormed the store, killing Lakdim and finding Beltrame gravely injured after being shot and stabbed.

After the gendarme was helicoptered to a hospital, France held its breath and hoped for a happy ending. At around 6am on Saturday morning, that hope was shattered.

A brief statement from the interior minister, Gérard Collomb, announced that Beltrame had made the ultimate sacrifice. Tributes poured in for the 45-year-old officer who, it was revealed, had been preparing to marry on 9 June. He had already married his wife, Mariele, under civil law, and the couple were planning a church ceremony. Instead, the priest who would have officiated at the wedding was called to Beltrame’s bedside, where Marielle was keeping vigil on Friday evening to give him the last rites.

French investigators are trying to discover how Lakdim, who had been flagged up by the country’s intelligence services as a security risk, was able to obtain a weapon and go on a killing spree, gunning down four people. The Trèbes attack is the first since Emmanuel Macron was elected last May and the first since France’s state of emergency was ended last November. While other European countries, Britain, Spain, Belgium among others, have been hit by terrorism, France has been especially targeted.

Apart from possible social and economic reasons that may drive disillusioned youngsters to extremism and France’s hard line on religious symbols like the burqa as well as the French military’s involvement in the US-led bombing of Syria, one reason France is targeted is that Isis specifically decided to target it. Islamic State’s chief spokesman, Mohammad al-Adnani, singled out the “spiteful French” for attack in September 2014.

Lakdim, who lived in Carcassonne, was known to police as a petty criminal and small-time drug dealer, and since 2014 he had been on France’s Fiche S list, meaning he was considered a potential threat. He had also been under surveillance, though intelligence officers reportedly decided he was not a serious risk.

Although French police knew he had consulted pro-Islamic State websites, French prosecutor François Molins said there had been no evidence he was planning a terrorist act.

Collomb agreed, saying Lakdim had shown “no sign of radicalisation”. He described his actions as that of “a loner who suddenly decided to act”. Islamic State claimed responsiblity for the attacks without giving any evidence. The claim is being investigated.

A second unnamed person, a male aged 17, was taken into police custody for questioning, and Lakdim’s girlfriend, 18, was brought in for police questioning on Friday evening.

Meanwhile, Beltrame’s family have been paying tribute to the courage of the officer. His brother Cédric said the gendarme would have walked into the supermarket knowing he would probably die.

“He certainly would have known that he had practically no chance. He was very conscious of that … he didn’t hesitate a second,” Cédric Beltrame told RTL radio, adding that it was “perfectly appropriate” to describe his brother as a hero. “He gave his life for someone else, a stranger, not even for someone in his family,” he said.

Beltrame’s mother also spoke to RTL on Friday before he died. “He used to say to me, ‘I’m doing my job, maman, that’s all.’ That’s just the way he is,” she said.

Florence Nicolic, Beltrame’s cousin, said that the gendarme had been passionate about the military all his life. “Since he was a little boy, Arnaud has always talked about the army and being a soldier. That has been a passion in his life since he was a baby,” Nicolic told the BBC. “He used to play with tin soldiers all the time. His grandfather was in the army and was an idol and he wanted to do it.”

She added: “What he did was so wonderful and so brave, we were very surprised and shocked. But when we heard what had happened, we were not surprised in a sense, because that’s the thing he would do without hesitation. He wouldn’t think about the consequences.”

Beltrame, of the Aude Gendarmerie, grew up in Brittany and had a distinguished career, earning commendations and military honours, including a military cross. He graduated from France’s elite military college, Saint-Cyr, in 1999 with the rank of major and a commendation for his “resolutely offensive spirit when faced with adversity”.

His superior officers noted that he was prepared to “fight to the end and never give up”.

From Saint-Cyr, Beltrame underwent training for the gendarmerie, including for the special intervention unit, the elite GIGN (Groupe d’intervention de la Gendarmerie Nationale), whose missions include counter-terrorism and hostage rescue. He was given military honours in 2007 following a two-year posting to Iraq and later spent four years as part of the Garde républicaine at the Elysée Palace, before becoming a special adviser to the secretary-general of France’s environment ministry. He was promoted to the rank of lieutenant-colonel in 2016.

“Lieutenant-colonel Arnaud Beltrame died serving the country to which he had already given so much. In giving his life to bring to an end the murderous actions of a jihadist terrorist, he has fallen a hero,” President Emmanuel Macron said.

As a former member of the elite anti-terrorist police, Beltrame had trained for such a situation. As deputy commander of the Aude Gendarmerie, he had organised an exercise simulating a terrorist attack and mass killing in a supermarket only last December. Even as they trained, Beltrame and his gendarmes must have thought such a scenario unlikely in a sleepy town like Trèbes. It now seems tragically prescient.