Brazil's truth commission has apologised for the government's "racist" maltreatment and detention of its large Japanese community during the second world war in a step that could open the way to compensation claims.

Twenty-five years after similar steps by the US and Canada, the move to make amends has been welcomed by groups representing the 1.5 million migrants and second and third-generation descendants in Brazil who now make up the biggest ethnically Japanese population outside of Japan.

After Brazil declared war on Japan in 1942, thousands of families from this community were arrested or deported as potential spies or collaborators.

The government also closed hundreds of Japanese schools, seized communications equipment and forced the relocation of Japanese who lived close to the coastline. A Japanese community in the northern Para state was restricted from travel.

Survivors have testified about the use of torture, and the degrading loyalty test in which Brazilian Japanese were forced to step on an image of Emperor Hirohito, who was then considered a deity in his country.

The truth commission saw video testimony of survivors and their children, including Akira Yamachio who said his father was arrested and tortured in Anchieta along with other prisoners: "A bit of the truth is better than silence," he said. "There inside [the penitentiary] there was persecution and torture. They ordered people to take off their clothes and pass through a 'corridor of death'," he said.

The commission made a formal apology and will include their findings in a final report to the government, which will also include other infringements of human rights in modern Brazilian history.

"I apologise and ask forgiveness on behalf of all Brazilian citizens with a generous view of society because the background of this episode is racism. The Brazilian elite have always been racist," Rosa Cardoso, a lawyer with the national truth commission, said.

She later told the Guardian the Japanese migrants had suffered from prejudice since they first started to arrive in the early 20th century. Many were from the poor northeast of Japan and thought they would be able to make their fortune overseas.

Instead, many ended up working in dire conditions on coffee plantations, or being given tranches of land in inhospitable areas. Most eventually moved to São Paulo.

After the Japanese imperial army's attack on the US fleet in Pearl Harbour, Brazil – which aligned with the allies – prohibited this community from reading or writing their own language.

"They were totally isolated culturally. Then many were imprisoned," said Cardoso. "It's time for us to ask forgiveness in relation to the Japanese. There has never been anything formal. I have now asked through the truth commission."

Japanese filmmaker, Mario June Okuhara, who recorded testimonies from many of those who suffered during that era in his film Yami no Ichinichi, thanked the truth commission and said the statement marked the beginning of the recognition of the violence suffered by a group of people who helped to build Brazil.

"There was a lot of torture, discrimination and violence, legitimised by the nationalism of that period," Okuhara said in a statement. "This was silenced during the dictatorship and many have forgotten it, like they have forgotten to speak Japanese ... Rescuing the truth about the arduous ordeal of the Japanese was a bold initiative."

Several other countries interred or maltreated large numbers of their citizens with Japanese heritage. In the wake of Pearl Harbour, the United States moved about 110,000 people into "war relocation camps", while Canada held 27,000 without charge and auctioned off many of their belongings. Redress came far earlier in those cases. The US government apologised in 1988 and paid out $1.6bn in compensation. A month later, Canada followed suit and subsequently gave $21,000 to each of the survivors as well as $36m to race-relations groups.

In Brazil, Fernando Morais, the author of a book about the detention, torture and killing of Japanese, German and Italian migrants during that era, said the next step should be compensation because the government had confiscated the money and property of people in those groups.

"Brazil should not only apologise. It owes money, a lot of money, to the Japanese community," he told the Globo newspaper. "The confiscation of assets is well documented in the Centra Bank's archives. Nobody ever got anything back."

• Additional research by Anna Kaiser