Ancient DNA from the bones of the biggest bird ever to exist has turned the evolutionary history of New Zealand's most iconic bird on its head.
Scientists have discovered the closest relative of the diminutive kiwi is the madagascan elephant bird.
Until now it was assumed the kiwi was an Australian migrant because genetic analysis showed it was more closely related to the emu and cassowary than the moa.
All these flightless birds, as well as others such as the ostrich, are part of a group called ratites. However there was one member of the family whose genome had never been investigated - the madagascan elephant bird.
The elephant bird was a giant herbivore, growing more then 3m tall. It got its name because when its bones were found the discoverers assumed they belonged to a bird so big it ate elephants. Their eggs were so big and had such thick shells a human could stand on them without without breaking them.
Alan Cooper, a New Zealand researcher at the University of Adelaide, has spent 25 years trying to extract DNA from Te Papa Museum's collection of 1000-year-old elephant bird bones.
At long last he has succeeded.
"We've been able to solve this evolutionary mystery that's been bedeviling us for 150 years and finally give an explanation of where the kiwi came from," Prof Cooper said.
When his team looked at the ancient DNA, they found it had far more in common with the kiwi than any other ratite.
Prof Cooper believes the elephant bird and kiwi had a chicken-sized ancestor which flew to both New Zealand and Madagascar from Antarctica 50 million years ago. It was a strange period in the earth's history, with no large herbivores; the dinosaurs had recently been wiped out and large mammals had not yet evolved.
In Madagascar, the ancient ratites grew to gigantic proportions to fill that gap but in New Zealand it was a different story.
"When it flew into New Zealand, 50 million years ago the moa was already in place and had already taken the niche of the large herbivore. The kiwi couldn't compete, it had to choose something else to do. An insectivore, eating insects, was the alternative lifestyle."
Another New Zealand kiwi researcher in Australia, Dr Trevor Worthy from Flinders University, said it was a significant discovery, especially given how little DNA could be extracted from ancient elephant bird bones.
"It's useful to think of a person walking into a room wearing a platinum ring. If they walk around a bit and then leave again they leave more platinum molecules in that room than there is target molecules of DNA in that test tube."
The research has been published in the academic journal Science.