Image caption Lapis stones for sale in Kabul

When David Cameron described Afghanistan to the Queen as "fantastically corrupt" over drinks at Buckingham Palace in April it was widely regarded as a gaffe. But the British prime minister was not wrong.

Afghanistan ranks a woeful 166th out of 168 countries in Transparency International's latest assessment of graft and crooked dealing around the world. And there is no better evidence of just how deep corruption goes than the fate of one of Afghanistan's greatest treasures, the gemstone lapis lazuli.

A two-year-long investigation by the campaigning NGO Global Witness shows that instead of going to the people, the profits from the trade in this extraordinarily beautiful semi-precious stone are being funnelled into the pockets of senior politicians and top officials, and have also become a major source of income for the Taliban and other insurgent militias.

Lapis is a vivid dark blue, like the sky at twilight or the ocean depths. Often it is flecked with specks of pyrite - fool's gold - which sparkle like tiny stars.

The greatest reserves of this "blue treasure" are in Afghanistan, where it has been mined from the same small area of a single river valley in the remote Afghan province of Badakshan for more than 6,000 years.

Media playback is unsupported on your device Media caption The BBC's Justin Rowlatt reports from Kabul: "The Afghan people are losing out on what should be a source of development"

Lapis pendants mined here decorated the necklaces of the princesses of the first ever city, Ur in Mesopotamia. Ancient Egyptian craftsmen used lapis from the same source to trace out the eyebrows of the young pharaoh Tutankhamun for his magnificent funeral mask.

Thousands of years later it was ground into dust and made into the most prized blue pigments. Medieval monks used the ultramarine inks and paints it created to illustrate exquisite manuscripts. Renaissance painters are said to have reserved its unique colours to depict the robes of the Virgin Mary.

Source of conflict

And lapis is still cherished for jewellery and ornaments today, but, says Global Witness, "an extraordinary national treasure that should be a powerful resource for reconstruction and development has become a major source of conflict and grievance."

And what is happening to lapis is a microcosm of the entire Afghan mining sector.

Image caption A pipe made from lapis on sale on Kabul's Chicken Street

According to the US Geological Survey Afghanistan has nearly $1trillion in untapped mineral deposits, enough to transform the impoverished nation's economy.

But illegal mining, operated with the connivance of senior politicians and insurgent groups, is robbing the country of this incredible wealth.

The United Nations has estimated that the income from minerals including lapis is now the Taliban's second largest source of income after opium.

Lapis lazuli:

Deep blue semi-precious stone prized since antiquity for its intense colour.

Mined in Badakhshan province in northeast Afghanistan as early as the 7th millennium BC.

At the end of the Middle Ages began to be exported to Europe, where it was ground into powder and made into the expensive blue pigment ultramarine.

Lapis usually forms in crystalline marble through the geological process of contact metamorphism (which causes transformation of rock through heat).

Most important mineral component is lazurite. Most deposits also contain calcite (white), sodalite (blue), and pyrite (metallic yellow).

All mineral resources in Afghanistan are the property of the government, but two years ago the lapis mines of Badakshan were seized by a warlord called Abdul Malik.

A senior government official told me "commander" Malik now effectively "owns" the mine and is earning millions of dollars a year by renting access to the ancient mine shafts out to illegal miners.

We met in the official's office in the centre of Kabul earlier this month. He was too frightened to be identified.

"The mine is under his control," he told me. "There are his people, he won't let soldiers or the police or anybody near".

He confirmed that Malik pays the Taliban protection money - "otherwise there would be fighting going on" - and told me he is protected by top politicians, who also receive payments from the warlord.

Global Witness estimates that the mining areas controlled by Malik contributed some $20m to armed groups in 2014 - the same amount as the government earned from the entire mining sector in 2013.

"At the moment more than 50% of the revenue that is coming out of the mine is being handed straight on to the Taliban", says the author of the Global Witness report, Stephen Carter.

"And the Taliban in Badakshan have close links to ISIS as well, so this is a very serious security issue."

A secret memo to the Afghan president Ashraf Ghani from his adviser on mines and obtained by the BBC, backs up Global Witness' claims.

"Unfortunately, we are still seeing known mafia groups robbing this precious resource with the help of local officials", the January memo from Mohammad Yousaf Pashtun says.

"Given the presence of mafia and extensive government corruption, it is now very difficult to control graft in this sector," he tells the president.

In his inaugural speech in September 2014 Mr Ghani made tackling corruption a top priority, but the story of how lapis is being stolen from the people of Afghanistan is powerful evidence of how much more the Afghan government must do.

Media playback is unsupported on your device Media caption David Cameron on "fantastically corrupt" countries attending a UK anti-corruption summit

The Afghan government needs to increase transparency and security in mining areas, says Global Witness. If it fails to do so, the NGO warns, the country's mineral resources will continue to entrench and perpetuate conflict in the country.

So, if you were wondering why corruption in Afghanistan should matter to you, here's why: the illegal trade in lapis shows how corruption can create the space for militant organisations like the Taliban to flourish.

It also undermines the legitimate economy, helping drive the huge wave of migration that Europe is currently struggling to manage.