There was a flash, a cloud of dust and a loud bang beneath an iron railway bridge, followed by a car alarm. The last known landmine in Mozambique had been destroyed, a victory many felt they would never see in their lifetime.

“That was a big boom,” said Cindy McCain, a veteran campaigner against landmines who, wearing protective visor and body armour, detonated the mine on Wednesday from behind a sandbag wall more than 100 metres away. “It would really hurt someone.”

Ash Boddy, programme manager of the Halo Trust, which has led demining efforts in the country for more than 22 years, replied: “Those are really dangerous, nasty mines.”

Perhaps happiest of all was Albert Augusto, director of Mozambique’s National Demining Institute, who had cranked up the detonator for McCain. “Now I’m jobless,” he joked.

Mozambique is set to declare itself the first heavily mined country in the world to be cleared of all known minefields on Thursday. Such claims seemed unthinkable when Princess Diana visited another Lusophone African country, Angola, with Halo in 1997. But brave and painstaking demining efforts, sometimes by hand, sometimes by heavy armoured digger, yielded results more quickly than anyone expected.

Augusto said: “Many people thought Mozambique would take a hundred years to demine the whole country. We ended up demining in less than 30. The key was the commitment of the government having a clear plan, doing it district by district, and the generosity of donors. Donors go anywhere there is a clear plan and they can see the value of money.”

Declaring a country mine-free seemed unthinkable in 1997, when Princess Diana visited the victims of landmines in Angola with Halo. Photograph: Joao Silva/AP

The antipersonnel mines were first planted in the 1960s during a war for independence from Portugal, then in a civil war that followed, and continued to inflict thousands of casualties long after peace was declared in 1992. Many were intended to restrict access to towns and were also placed around dams, electricity pylons, railway bridges and other infrastructure to protect them from guerrilla attacks or sabotage.

Zimbabwe, then known as Rhodesia, laid mines along its border in the 1970s to stop guerrilla infiltrations, making it one of the most thickly mined corridors on the planet. Numerous mines still remain on the Zimbabwean side, menacing both Zimbabweans and Mozambicans who regularly move back and forth.

Halo began operations in Mozambique in 1993, funded by the US, UK and others to the tune of nearly $57m (£37m), with hurdles including the rainy season that made work impossible for certain months each year. Mines were typically planted 5cm beneath the surface but some were deeper and beyond the range of conventional metal detectors. They included Soviet-era PMD-6 wooden “shoe-box” mines, containing 200g of TNT, and American M14 mines with little metal content, requiring specialised equipment normally used for detecting gold. Halo has suffered four fatalities in all.

Boddy said: “In 2007 we were already talking about donor fatigue and an unsolvable problem. But then we did a baseline survey and said, ‘This is what it’s going to take to clear the rest of the country.’ We now had a tangible end state that all the operators could work towards.”

In the early 1990s, around 600 casualties per year were reported; by 2013 this had dropped to 13. With a combination of manual and mechanical clearance, Halo has now destroyed more than 171,000 mines and cleared 1,118 minefields, roughly four-fifths of the total removed by all operators at a total cost estimated in 2012 at $285m.

Calvin Ruysen, regional director of Halo in southern Africa, said: “This is the first heavily mine-affected country to reach an end state. That’s a massive story because it demonstrates that, with the right approach and resources, you can bring a problem to conclusion. It’s an example to other heavily affected states: the fact we’re here now is very important.”

The global fight against landmines has achieved notable successes. Since the Mine Ban Treaty came into effect in 1999, the use and production of mines has nearly halted, casualties have sharply reduced and 27 affected countries have declared themselves free of mines. But the International Campaign to Ban Landmines said last year around 4,000 people are still killed or injured annually in 60 countries.

Mozambique’s final chapter unfolded at the Dondo bridges and viaducts in Sofala province, which had been mined by the governing Frelimo to defend against the rival rebel movement Renamo. Here Halo has destroyed 314 mines, each marked by a white stake in the ground, and cleared five minefields spanning 36,000 square metres. On 26 August local people expressed relief that the decades-long cloud had lifted.

The Dondo bridges in Sofala province where the final mine clearance took place: ‘I told my family not to walk through the viaduct. I was always worried about my children,’ said a local farmer. Photograph: Ryan Daniels

Tome Francisco, 76, a farmer, recalled how in 2010 a local man was killed. “I heard the explosion and ran over there,” he said, sitting outside a nearby house made of dried grass and mud. “It was raining and the man was trying to cross the viaduct and stepped on a mine. It blew off one of his legs but he was still conscious. My friend and I collected him and took him to the hospital but he died.

“I thought, what is going to happen now? Is an organisation going to come and clear landmines? I told my family not to walk through the viaduct. I was always worried about my children. When I saw the Halo Trust here, I was very happy. Now we are free and there are no more landmines. We can cultivate the land without a problem.”

As a train rumbled slowly overhead, carrying petrol and granite blocks from Zimbabwe to the Mozambican port of Beira, Joakin Sata, 60, walked by with his bicycle. “I saw soldiers planting these mines,” he said. “They came to my house and said they were planting mines to protect us from Renamo.”

It did not take long for Sata’s cousin to tread on a mine and lose a leg while returning home from work one day. “There were no warning signs and the mines were well hidden,” continued Sata, whose home sits under a mango tree less than 100 metres away. “I was afraid because I had kids. I had to be strict with them and was always telling them, ‘Don’t go too close’. But now we can run wherever we want.”

Further along the 19th-century railway line, beneath a rusting bridge that spans the Pungue river, four 16-tonne armoured diggers with US flags and two 13-tonne Hitachi 130 excavators stood to attention. Neat rows of white stakes showed where the mines had been found, some with the help of a mechanical sifter. Boddy said: “It was a truly fascinating, intricate task because every square metre was different. We are confident that we can walk away from this task knowing every mine is clear.”

Mozambique’s last known mine, a Hungarian-made Gyata-64, was made of bakelite with a black rubber top and 300g of explosive calculated to sever a leg above the knee. Halo placed it in a crater behind a red danger sign with a skull and crossbones and attached an explosive and fuse. Its sentries warned a local woman and some children to stand well clear.

After the detonation, about 70 Halo staff lined up to receive commemorative medals from Augusto and McCain, chairwoman of Halo US and the wife of US senator John McCain. She said: “It’s hard to explain because it’s so monumental. In a country like Mozambique, the people have lived in fear most of their lives and children have been born in fear. This gives the country back its land and the children can be safe now. It’s a great boost for other countries because they can see it’s finished.”

She added: “I was here 20 years ago and there were mines everywhere. I couldn’t get it in my head how we could finish it. Mozambique represents hope and future to the rest of Africa. We have many countries that are still terrorised by landmines: Angola, Zimbabwe, Somaliland. Mozambique has made us realise that we can do this, we can finish it, but not without a lot of help along the way.”

It was also an emotional day for Felberto Manuel Mafambese, the traditional chief in the area, who saw people killed and injured by mines during the civil war. “The mines were like a second war,” he said. “As a community we were under pressure. Every time I went outside, I didn’t know if I’m going to step on a landmine.”

He added: “It’s difficult to explain what I’m feeling. It means we can develop our cultivation and plans. The second war is finished and we are free.”

Mozambique was the first country where Halo employed female deminers. Flora Moreira, a 30-year-old single mother of three, had to overcome resistance from her mother to get involved. “My mum is proud of me now because nothing happened to me. People say women cannot demine: only men can do that hard job. It has been hard but I’ve learned that women can do it.”

The Halo Trust’s local deminers are to receive paid tuition to attend vocational training courses now that the minefields are cleared. Photograph: Ryan Daniels

Moreira hopes to take her demining experience abroad because Halo’s local staff now find they have put themselves out of a job. A total of 1,600 national employees was reduced to 450 last year and is down to 174 now with further cuts to come. All will receive paid tuition to attend vocational training courses ranging from car repair to small business management.

Augusto said: “Demining is over but we don’t want deminers to die. We can train them for other things. We don’t want them to be upset because they finished the job. We want to give them more opportunities. They did a good job but we also want them to continue living.”

He acknowledges that not every mine can categorically said to have been removed but plans to train two police officers in each district to deal with any remaining outliers. “There will still be some. We never had a map in Mozambique. But we think we are not going to find a contaminated area. We can find one mine here, one mine there, but we don’t expect to find a minefield.”

That milestone has a special resonance for Nguila Nhamposse, who lives in the village of Gumbane near the capital, Maputo. In 1993, the year that Halo began its operations, he saw a neighbour blown up by a mine and, in trying to recover his body, stepped on one himself. “It seemed like it was night,” he remembered. “I heard the bang – it was very loud. My body was blue because of the smoke but I thought my leg was still there. I only realised I’d lost a leg when I got to the hospital.”

Nhamposse’s wife left him soon after, citing his inability to provide for the family. “My emotions were like the time I lost my leg. I felt my life would be difficult. How was I going to move? When I stood up it felt like a wall in front of me.”

Now 78, he has short curly hair, a greying moustache and crooked teeth. His two walking sticks are worn down by 20 years of use and get stuck when the ground is muddy. “It’s hard to carry a bucket of water for a shower. I’m facing many difficulties to have food to eat. Even the children are running away from the house because their father is not able to find food. I think many things about my life.”

Asked about his feelings towards those who planted the mine, Nhamposse paused and replied: “I cannot say anything. All I can say is thank you to the people who removed the mines. It was not only for me but for everyone here.”

