She arrived in New Zealand on a visitor permit in December 1986, and it expired in March 1987.
Her children are all New Zealand citizens.
Matagitau's parents moved from Samoa and became permanent residents in 2001 after she applied for a visa through the family category.
During the process, she discovered she was not a resident, so got a six-month visitor visa.
When it ran out in December that year she did not try to get another one.
Matagitau tried to renew her Samoan passport in 2013, but authorities told her she was unlawfully in the country.
Then last May, Matagitau was detained and served with a deportation order.
She described being in a police cell and waiting to be deported as the worst time of her life.
"I was crying and thinking of my children and grandchildren, and how I may never see them again," Matagitau said.
"I was worried for them, but I prayed and I prayed really hard and never lost hope."
Immigration lawyer Kamil Lakshman, who Matagitau's family contacted while she was being detained, got a one-day visitor visa from the former associate immigration minister so she could appeal to the Immigration and Protection Tribunal on humanitarian grounds.
After what has been described as "a long and arduous process", the tribunal found last month that Matagitau had grounds to remain in the country.
"While the period she has been unlawfully in this country has been an extremely long one, it is accepted that for a good proportion of that time [she] genuinely believed she held residence status," tribunal member Moana Avia wrote in her decision.
Avia agreed that if Matagitau had received competent advice earlier, her immigration situation could have been resolved much earlier.
The tribunal found there were "exceptional circumstances of a humanitarian nature" and that it would be unjust or unduly harsh for her to be deported.
Matagitau broke down in tears when she was presented with her passport and the resident visa on Wednesday.
"After so many years I am finally free, it is really a miracle," Matagitau said.
"I want to say thank you Lord, thank you Jesus and thanks to my lawyer for everything that you have done for me and my family."