Revelations from the Panama Papers show how a company based in Jersey, a British crown dependency, attempted to avoid paying $400m (£280m) in Capital Gains Tax to the Ugandan government, writes BBC Africa's Rob Wilson.
In 2010, Heritage Oil and Gas Ltd realised it would be hit with a huge tax bill and started making efforts to avoid it by moving the country where the company was registered from the Bahamas to Mauritius, leaked emails obtained by the International Consortium of Investigative Journalists and shared with the BBC show.
Mauritius has a double-tax agreement with Uganda, which in principle means companies pay tax in only one of the two countries.
Since Mauritius does not impose any Capital Gains Tax, charged on the sale of assets, this would mean Heritage reduces its bill to zero.
One of the emails written by an accountant acting on behalf of Heritage said the move to Mauritius would act as a "second line of defence" in efforts to "eliminate the potential tax charge imposed by the Ugandan authorities".
Elsewhere, he was more precise: "We are looking to re-domicile Heritage Oil and Gas Ltd. [HOGL] to Mauritius (primarily due to the double tax agreement between Uganda and Mauritius). HOGL… is due to complete the sale of an asset in Uganda within the next 11 days.
"Due to tax reasons emanating from Uganda, the directors have been advised by tax accountants to re-domicile HOGL to Mauritius from the Bahamas before completion."
In the paper trail, the Panama-based law firm at the centre of the massive data leak, Mossack Fonseca, is named as the registered agent of Heritage, whose founder Tony Buckingham is, according to the London-based Guardian newspaper, a donor of UK Prime Minister David Cameron's Conservative party.
The legal services head of the Uganda Revenue Authority (URA), Patience Tumusiime Rubagumya, told the BBC that the "re-domiciliation of Heritage had tax avoidance manoeuvres written all over it".
But the leaked email trail is the first direct insight into the thinking of the oil company's managers and those acting on their behalf.
"The leaks, if true, only go to validate the position taken by URA as far back as January 2010," Ms Rubagumya added.
Panama Papers - tax havens of the rich and powerful exposed
- Eleven million documents held by Mossack Fonseca have been passed to German newspaper Sueddeutsche Zeitung, which then shared them with the International Consortium of Investigative Journalists. BBC Panorama and The Guardian are among 107 media organisations in 76 countries which have been analysing the documents. The BBC does not know the identity of the source
- They show how the company has helped clients launder money, dodge sanctions and evade tax
- Mossack Fonseca says it has operated beyond reproach for 40 years and never been accused or charged with criminal wrongdoing
- Tricks of the trade: How assets are hidden and taxes evaded
- Panama Papers: Full coverage; follow reaction on Twitter using #PanamaPapers; in the BBC News app, follow the tag "Panama Papers"
- Watch Panorama on the BBC iPlayer (UK viewers only)
Heritage did not respond to the BBC's request for comment, but told the The Guardian that "it is a fact that the process of re-domiciling one of Heritage Oil's subsidiaries from the Bahamas to Mauritius had begun long before the completion of the transaction that ultimately gave rise to the tax dispute with the Ugandan government. The process of re-domiciling was commenced for a variety of reasons."
The dispute over the $400m tax bill has been dragging on since 2010 in a lengthy series of court battles in both Uganda and the UK.
After the issue was brought to the attention of Uganda's tax authority, a Tax Appeals Tribunal heard the case, as the company denied it was liable to Capital Gains Tax on the sale of its assets.
While the tribunal ruled in favour of Uganda, Heritage disputed the decision and the case was moved to a court in London and dragged on for months.
In the meantime, the Ugandan government clamped down on the new owners of the oil assets, Tullow Uganda Ltd, and relations between the two started to break down.
In an attempt to salvage its business operations in Uganda, Tullow paid the Ugandan government and later successfully sued Heritage to reclaim the money.
In a region littered with mineral deposits of many sorts, and brimming with exploration being carried out by foreign companies, the revelations contained in the Panama Papers highlight the need to tighten tax laws, says Ms Rubagumya.
"Base erosion and profit shifting through aggressive tax planning, treaty abuse and double non-taxation requires concerted effort from the revenue authorities and policy makers," she told the BBC.
"African countries should therefore close all potential loopholes and stand firm to ensure that tax due is paid."