“There is no doubt that the problem of global tax avoidance generally is a huge problem,” Obama told reporters at the White House on Tuesday. “The problem is that a lot of this stuff is legal, not illegal.”

The US president said the leak from Panama illustrated the scale of tax avoidance involving Fortune 500 companies and running into trillions of dollars worldwide.

“We shouldn’t make it legal to engage in transactions just to avoid taxes,” he added, praising instead “the basic principle of making sure everyone pays their fair share”.

Obama described the Panama revelations as “important stuff” and highlighted the impact upon ordinary citizens, adding that “a lot of these loopholes come at the expense of middle-class families, because that lost revenue has to be made up somewhere.

“Alternatively, it means that we’re not investing as much as we should in schools, in making college more affordable, in putting people back to work rebuilding our roads, our bridges, our infrastructure, creating more opportunities for our children.”

Obama spoke in favour of his administration’s new rules to close corporate inversions, by which companies move their headquarters overseas to avoid taxes. He described the practice as “one of the most insidious tax loopholes out there”.

His unscripted remarks came as he made a rare and unscheduled appearance in the White House press briefing room and follows confirmation that US authorities are reviewing an international offshore law firm, exposed for helping the wealthy and powerful avoid US sanctions against regimes in Syria, North Korea, Russia and Iran.

Obama administration officials confirmed that they are examining reports based on the leak of millions of documents from the Panama-based law firm Mossack Fonseca. The documents were leaked to Süddeutsche Zeitung and shared with the International Consortium of Investigative Journalists (ICIJ) and a large network of international partners, including the Guardian and the BBC.

“We are aware of the reports and are reviewing them. While we cannot comment on the specifics of these alleged documents, the US Department of Justice takes very seriously all credible allegations of high-level, foreign corruption that might have a link to the United States or the US financial system,” said Peter Carr, spokesman for the DoJ.

The White House spokesman, Josh Earnest, said in remarks on Monday there “should be greater transparency in international financial transactions”.

High-end property sales linked to offshore accounts are likely to be one area of interest for US authorities. The documents link offshore accounts to buyers of high-priced property in Miami, one of a number of cities to have experienced a property boom fuelled by buyers with offshore accounts.

The papers link one $3m cash purchase of a Miami apartment to Paulo Octávio Alves Pereira, a Brazilian developer and politician now under indictment for corruption in his home country.

Earlier this year federal agents announced a crackdown on corrupt foreign officials and criminals snapping up high-priced real estate in the US in cities including Miami and New York.

Leftwing Democratic presidential candidate Bernie Sanders said: “Children should not go hungry while billionaires use offshore tax havens to avoid paying their fair share of taxes.” He used the leak to attack his opponent, Hillary Clinton, for supporting a 2011 free trade deal between the US and Panama. “I wish I had been proven wrong about this, but it has now come to light that the extent of Panama’s tax avoidance scams is even worse than I had feared,” he said.

The Vermont senator said that if elected president he would “terminate” the Panama agreement within six months and “conduct an immediate investigation into US banks, corporations and wealthy individuals who have been stashing their cash in Panama to avoid taxes. If any of them have violated US law, my administration will prosecute them to the fullest extent of the law.”

Mossack Fonseca has operations in Nevada, the Guardian can disclose, which could create another area of difficulty for the firm. According to the leaked papers Mossack Fonseca’s employees attempted to “obscure” documents and “clean” computer logs after it was issued a subpoena by a federal court in Las Vegas.

Internal emails show that a Mossack Fonseca employee travelled from Panama to the Nevada office. “When Andrés came to Nevada he cleaned up everything and brought all documents to Panama,” reads a 24 September 2014 email.

Another email from 2014 said it was important that any links between the company’s computers in Panama and Nevada “has to be obscure to the investigators”.

Mossack Fonseca said it “categorically” denied destroying any documents. “Let us be clear that it is not our policy to hide or destroy documentation that may be of use in any ongoing investigation or proceeding,” a spokesman for the company said.

Eric LeCompte, executive director of the Jubilee USA Network, a Washington-based faith advocacy group, said: “These actions demonstrate how important this leak is and how many people desperately wanted to stop it from coming to light. Nevada is a hub for financial secrecy in the United States. Nevada-based shell companies have been used to scam US military personnel, churchgoers and the elderly. The US must pass legislation that shines a light on these secretive shell companies.”

Another leaked email from a Mossack Fonseca partner said: “Ninety-five percent of our work coincidentally consists of selling vehicles to avoid taxes.” The company denies any wrongdoing. The creation and use of an offshore company to avoid tax is not against the law.

The revelation that a company engaged in industrial-scale offshore tax avoidance, even on US soil, comes after Obama has repeatedly spoken out against companies and the super-rich exploiting the US tax code..

Soon after he took office in 2009, Obama outlined plans to crack down on offshore tax havens and return more than $200bn in unpaid taxes to the US. “I want to see our companies remain the most competitive in the world. But the way to make sure that happens is not to reward our companies for moving jobs off our shores or transferring profits to overseas tax havens,” he said. However, eight years on little has changed and indeed the US itself has emerged as a popular venue for tax avoidance.

The US states of Nevada, Wyoming and South Dakota have been promoted as new hot markets to avoid tax and stash cash secretly, because the US has been resisting international disclosure reforms. Last year the Tax Justice Network, an activist research group, ranked the US third in its annual financial secrecy index, citing its “wide array of secrecy and tax-free facilities for non-residents”.

“How ironic – no, how perverse – that the USA, which has been so sanctimonious in its condemnation of Swiss banks, has become the banking secrecy jurisdiction du jour,” Peter Cotorceanu, a lawyer at the Swiss law firm Anaford AG said in a recent legal journal, according to Bloomberg. “That ‘giant sucking sound’ you hear? It is the sound of money rushing to the USA.”