John Key didn't know how deep the links with Malta really ran.

When New Zealand Prime Minister John Key flew into Malta for the Commonwealth Heads of Government Meeting in November 2015, he already knew he shared some important views with his host, Malta's Prime Minister Joseph Muscat, about the importance of keeping the tax secrets of foreign investors.

Both countries are quiet achievers in the ranks of global tax havens, and both are determined to keep it that way.

While Malta has been fiercely resisting pressure to close tax avoidance loopholes used by foreign companies, including Australian firms, to move profits out of the European Union, New Zealand has fought just as hard to protect its laws that make foreign profits tax-free and invisible for beneficiaries of its offshore trusts.

But what Key didn't know, as he and Australia's Prime Minister Malcolm Turnbull mingled with Muscat at CHOGM, was how deep those links really ran.

READ MORE: Money laundering on a global scale revealed in massive document leak

Just weeks earlier, Muscat's chief-of-staff, Keith Schembri, and Malta's energy minister, Konrad Mizzi, had used New Zealand's secrecy laws to set up two offshore trusts. These were to be linked to a secret Dubai bank account and to two Panama companies that Schembri and Mizzi had set up in 2013 through a Panamanian law firm.

The revelation of the New Zealand trusts has triggered ongoing crisis for Muscat's government, but it also increases pressure on New Zealand to tighten its tax loophole for foreign trusts.

New Zealand's 12,000-plus offshore trusts pay no New Zealand tax on foreign earnings. Their beneficiaries are not registered and their accounts are not filed with any public body. New Zealand regulators may demand this information, but it is not disclosed to foreign governments.

LAW FIRM TIES IT TOGETHER

Details of the Malta controversy, and its New Zealand connections, have emerged from 11.5 million tax haven records obtained by the International Consortium of Investigative Journalists (ICIJ), the German newspaper Süddeutsche Zeitung and more than 100 other media partners worldwide.

The common thread is a Panamanian law firm with considerable influence in the Pacific, Mossack Fonseca.

In 1996 Mossack Fonseca won a 20-year exclusive right to operate offshore companies in the tiny island state of Niue, 2000 km north-east of New Zealand, with a population of 1190. The Panamanian firm even wrote the Niue legislation.

When international pressure forced the closure of the Niue business in 2004, Mossack Fonseca moved its client companies to Samoa, but its links to New Zealand remained strong.

Malta's own corporate structures are used by a range of Australian companies to minimise tax.

They include Macquarie Group, which interposed two Malta subsidiaries between Luxembourg and Bermuda operations, after Macquarie acquired Lend Lease Global Properties.

In 2015, Commonwealth Bank chief executive Ian Narev was questioned at the Senate banking inquiry about the disproportionately large number of loans written by the small number of staff in the bank's Malta subsidiary, and about the low level of tax paid there.

Narev said the subsidiary was located in Malta solely because the bank needed a position in Europe to write loans for European clients.

But the release of tax haven records through the ICIJ underline the ease with which even foreign politicians can use New Zealand to hide their wealth.

In February 2016, as Malta's Prime Minister Muscat again said Malta would resist European Community pressure to share tax information, his energy minister Mizzi confirmed reports that he had set up a trust in New Zealand.

Mizzi said the Rotorua Trust, which is operated by a Mossack Fonseca trustee company, Orion Trust (New Zealand) Limited, had no funds and owned only a shell company in Panama, Hearnville Inc, that had never been used.

"This may be used in the future to hold my existing property and possibly investments. Currently the trust does not have any bank accounts," he said. "The trust was set up for long-term family asset management and inheritance.

"The trust is regulated and registered in New Zealand, a stable parliamentary democracy that is one of the world's most well-governed nations, having ranked in the top tier of indexes on the strength of its democratic institutions, government transparency and lack of corruption."

The Mossack Fonseca documents tell a more complicated tale. They show that the PM's chief-of-staff Schrembri used a Spanish adviser to set up a British Virgin Islands company, Colson Services Ltd, for him in January 2011.

On the same day, a second BVI company, Selson Holding Corporation, was set up for Malcolm Scerri, the managing director of Schrembri's Maltese company, Kasco Limited.

Four months later, on May 10, 2011, Adrian Hillman, the managing director of Malta's major newspaper company, Progress Press, set up a third BVI company, Lester Holdings Group Limited, through the same Spanish intermediary.

Last month Hillman resigned after claims by a Maltese blogger, Daphne Caruana Galizia, that Schembri had made payments to Hillman's BVI company as an inducement for Progress Press to buy newsprint from his firm Kasco.

Hillman and Schembri both deny the allegations.

In August 2013, Mossack Fonseca set up two Panama companies, Hearnville Inc and Tillgate Inc, which outwardly were owned and controlled by a Mossack Fonseca firm, ATC Administrators Inc.

But in reality Hearnville was controlled by Malta's energy minister, Mizzi, and Tillgate by the PM's chief of staff, Schembri.

The two companies were dormant until June 2015, when Mossack Fonseca in New Zealand set up the Rotorua Trust for Mizzi and the Haast Trust for Schembri, with ownership of the two Panama companies transferred to the trusts.

As foreign trusts operated by trustee company Orion Trust (News Zealand) Limited, Rotorua and Haast face no tax scrutiny in New Zealand of any Panama income.

By August 8, the Mossack Fonseca franchise firm in Malta, which acts for Mizzi and Schembri, was writing to Mossack Fonseca Panama: "We are in the process of opening a bank account in Dubai for two of our Panama companies."

The unnamed bank was asking for full documentation for Hearnville and Tillgate, including the names of the real owners.

As the clients in Malta (Mizzi and Schembri, acting through their local Mossack Fonseca office) pressed to obtain the documents to set up the Dubai account by August 28, Mossack Fonseca in Panama became concerned that both Schembri and Mizzi were "PEPs", or Politically Exposed Persons.

"As both settlors [that is, the parties that set up the trust] are PEP, our NZ colleagues need to be comfortable that sufficient due diligence has been carried out to ascertain that funds being settled are not subject to any corruption risk, and ideally that they come from income generated prior to the settlors' political appointment," a Mossack Fonseca operative in Panama wrote.

"With respect to Haast Trust, it would appear that there was some negative coverage regarding the tender process for supply of paper to the government shortly after the settlor's appointment as Chief of Staff, so if you could also include a detailed information about this, that will be a very important information for us as well."

A follow-up email noted that "there is also some negative publicity regarding the amount of remuneration for KM's [energy minister Konrad Mizzi's] wife".

Mossack Fonseca also sought more information on what the companies would do, as "the reference to 'management consultancy and brokerage' does not explain this".

No further reference was made to the Dubai account, but meanwhile FPB Bank in Panama had refused to open an account for Hearnville and Tillgate after learning the identity of the Ultimate Beneficial Owners (UBOs) of the companies.

The bank offered several reasons for the knockback, but "the principal of them [is] that the UBOs of the said companies are PEP", the Mossack Fonseca executive wrote.

He said, somewhat obscurely, that Mossack Fonseca had referred the matter to "two persons who will help us with these bank accounts".

The documents show Mossack Fonseca's chief concern was to be able to show they had taken some steps to verify the bona fides of clients.

In an unrelated matter in late 2015, Mossack Fonseca was setting up a New Zealand trust for a different client, which would be titled Humanitarian Intervention Relief and Research Trust, also with a Panama company.

The chief beneficiary of this charitable trust would be Gabriel José Pretus Becerra, who was also a PEP.

Becerra "had been prosecuted by the Criminal Court of Spain for a presumable fraud and money laundering, but the Court ruled in favour of Becerra absolving him from any charge", a Mossack Fonseca operative noted.

Back in Malta, in February 2016, Schembri told journalists he "was informed of the possibility of my local bankers changing their business model or transferring their trusts business to third parties".

"My New Zealand-based trust, together with any attached company, which has not traded so far, was opened as a contingency for this reason upon advice from my financial advisers.‎ I will also be asking a reputed auditing firm, independent of my financial advisers, to audit the New Zealand-based trust and related operations, and will make this report available to the media."

Mizzi confirmed the existence of his New Zealand holdings, releasing a statement by Orion Trust (New Zealand), signed by Giselle Ocampo Fonseca, that Rotorua Trust "does not, as to date [sic], have any bank account in its name and Orion does not hold any bank accounts in the Trust's name".

This careful wording appears to be accurate.

On February 29, Mizzi announced he would close down his Panama company after a tax audit, but would retain the New Zealand trust.

As the Malta controversy deepened, by late last month the embattled prime minister Muscat was ready to take a break.

He spent the Easter holiday at Atlantis the Palm, a five-star resort in Dubai.

Sign up to receive our new evening newsletter Two Minutes of Stuff - the news, but different