The victims — the youngest only six months old — were trapped inside the house in Ambalavato village of Ikalamavony district in the rural centre of the island.
The party-goers, including several relatives of the home owner, were celebrating the renovation of the same house in which they perished.
“Of the 39 people in the house, 38 were killed, including 16 children,” Herilalatiana Andrianarivosona, spokesman for the police, told AFP, adding that the fire was an accident.
“A celebration had been held following the completion of the renovations to the house,” he added.
The blaze is believed to have started from embers of a fire that had been used earlier to cook food for guests.
It was swept by winds, spreading first to a bale of dry rice straw adjacent to the house before it caught hold of the grass thatch on the roof.
Other villagers tried to rescue the people trapped inside but failed to open the door.
Only one 14-year-old boy managed to escape the inferno by jumping through a small window, police said.
Narrow windows to deter burglars are part of the design of many houses in the central region of the impoverished Indian Ocean island.
Due to crime and frequent muggings, the party guests chose to stay at the host’s house rather than return home at night.
Funerals for the 39 victims were held on Monday.
Madagascar is one of the world’s poorest countries and relies heavily on international donors.
After a period of political instability triggered by the 2009 ousting of president Marc Ravalomanana by Antananarivo’s then-mayor Andry Rajoelina, it is struggling to foster an economic recovery.