Image copyright AFP/Getty Image caption UN Security Council members cast their vote during a meeting on the election of five members of the International Court of Justice.

The International Court of Justice is the principal legal body of the United Nations. It is based in The Hague and its job is to settle disputes between states.

Lots of its work is highly technical and not exactly the stuff of the front pages. And let's be honest, many people would probably not have known that one of the 15 judges had always been British ever since the court was set up after the Second World War.

But the loss of a British presence around that supreme judicial bench is of huge significance - not just to the court but to the UK's standing in the world.

This is how it happened. Five of the 15 judges are elected every three years to ensure continuity. Britain's judge, Sir Christopher Greenwood, was hoping to win re-election for a second nine year term. He is a highly distinguished lawyer and former professor in international law at the LSE.

More from James:

But there was a hitch. Rather unexpectedly, Lebanon's former ambassador to the UN put his hat in the ring. So instead of there being five candidates for five places, now there were six.

And the former ambassador, having spent many years at the UN, had enough friends to win the election. He won one of the slots reserved for candidates from Asia. This meant the Indian candidate - Dalveer Bhandari - had to try his luck for a slot normally reserved for Europeans and in this case that meant challenging the UK.

In recent days, the four other candidates were elected. But while Sir Christopher won the support of the UN Security Council, the Indian judge was backed by the UN General Assembly. A successful candidate needs a majority of support in both bodies. And after repeated votes, there was deadlock.

UK has had ICJ judge since 1946

The Indian government was working hard, twisting arms, lobbying furiously, pulling in favours. The Indian newspapers were full of accusations that the British were using "dirty tricks" to try to win. Some commentators compared Britain's behaviour to its old commander in chief of British India, Robert Clive. Few anti-colonialist tropes were left unused.

In contrast, British ministers made some telephone calls. The British did consider invoking a little known provision in the UN Charter which allows for an arbitration process known as a "joint conference" to try to resolve such an impasse.

Image copyright Reuters Image caption Matthew Rycroft, the UK's ambassador to the UN, said he was "pleased" that a "close friend like India" had won.

But in the end, the UK chose not to use this process, fearing either it would not get enough support in the UN Security Council, or that the competition would become too bitter and potentially disrupt the UK's economic relations with India.

Either way, it means that from early next year, when Sir Christopher stands down, the UK will not have a judge on the ICJ for the first time since 1946.

On one level, this reflects a shift in the balance of power at the UN away from the Security Council. Many members on the General Assembly resent the way the Security Council has so much power, particularly the five permanent members.

The so-called Group of 77 - which represents a coalition of mostly developing nations - has long been pushing for greater influence. The victory of India over the UK will be seen as a huge success for the G77 in pushing back against the traditional northern powers on the security council.

Diplomatic set back?

Foreign Office sources pointed out that the UK's ousting from the ICJ is not without precedent. They pointed to France failing to get its candidate onto the International Law Commission last year and Russia's exit from the Human Rights Commission.

But it is also true to say that this represents a defeat for the UK itself. This is a failure of UK diplomacy. Downing Street refused to confirm that Theresa May herself got involved in lobbying for this job - they merely said representations have been made at the highest levels of government. But Boris Johnson and his Foreign Office ministers were certainly involved. And they failed. They failed to win enough support in the General Assembly.

Matthew Rycroft, the UK's highly rated ambassador to the UN, said the UK had folded because it did not want to take up more of the UN's valuable time, and he said he was "pleased" that a "close friend like India" had won. Perhaps more frankly, he admitted that the UK was "naturally disappointed".

However hard the government tries, this defeat at the UN will be seen as a significant diplomatic set back, a symbol of Britain's reduced status on the world stage. Britain tried to win an election - but the community of nations backed the other side, no longer fearing any retribution from the traditional powers, no longer listening to what Britain had to say.

Some will blame this on Brexit. That might be a little simplistic. Few countries are as obsessed with Brexit as the UK. It is simply not at the front of their minds. But what is clear is that many countries at the UN were willing to defy Britain and that would have been less likely a few years ago.

The government likes to talk of what it calls "global Britain", a vision of a buccaneering UK, independent of the EU, promoting its interests and values and trade around the world. The problem is that many believe that vision has not yet been backed up with any policy substance.

Instead, rightly or wrongly, many countries see the UK turning in on itself to sort out the complexity of Brexit. They see it as a retreat from the international stage - whatever the Brexiteers argue to the contrary - and these countries are filling the vacuum accordingly.

We saw a sign of this earlier in the year in June, when the UN general assembly voted against Britain to refer a dispute between the UK and Mauritius over some islands in the Indian Ocean, to the International Court of Justice.

In another age, Britain would perhaps have called in favours, flexed its P5 muscles, and taken the fight to India. But instead it withdrew, at best to take a short term hit probably to avoid a long term economic loss. At worst it simply gave up because it had no alternative and as a result, for the first time in 71 years, the UK will no longer be represented in the world's highest court.