A massive fire has raced through Brazil's 200-year-old National Museum in Rio de Janeiro, likely destroying its collection of more than 20 million items, ranging from archeological finds to historical memorabilia. 

The museum, a cherished historical repository, lacked a sprinkler system and was reeling from years of financial neglect, making its destruction a "tragedy foretold."

The one-time Imperial Palace's pastel-yellow facade remained standing but a peek inside its giant windows revealed a roofless interior of blackened hallways and charred, smoldering beams.

Every so often, firemen emerged with a pot or a painting they had managed to rescue.

Authorities said the cause of the blaze was not yet known.

Researchers, students and others who worked in the museum, where 20 million archives were likely destroyed, huddled in small groups outside the ruined building, consoling one another and wiping away tears.

The fire has stirred emotions in Brazil, whose angry electorate is reeling from a frail economy, widespread graft and rising violence ahead of an unpredictable presidential electionin October.

Luiz Duarte, vice director of the museum, told Globo TV the institution had been neglected by successive federal governments, and that a financing plan announced in June included a plan to install modern fire protection equipment.

Roberto Robadey, commander of the Rio fire department, said the two hydrants outside the building were dry.

That forced firefighters to use water from a nearby lake and rely on water trucks. But the building burned far too fast for any of that to help.

"In an ideal world, we would have many things that we don't have here - sprinklers inside the building," he said, adding that the fire department would investigate its response and take action if needed.

Renato Rodriguez Cabral, a teacher in the geology and paleontology department, said the museum's decline did not happen overnight.

"This was a tragedy foretold," Mr Cabral said, "Successive governments would not provide funds, they would not invest in infrastructure."

Mr Cabral said the building received new wiring about 15 years ago, but that clearly there was not a sufficient plan to protect the museum from fire, adding: "The firefighters basically could only watch the blaze."

"For Brazilian history and science, this is a complete tragedy," he added. "There is no way to recover what was lost."

The National Museum's collection ranged from archeological finds to historical memorabilia.

The museum, which is tied to the Rio de Janeiro federal university and the education ministry, was founded in 1818. It housed several landmark collections, including Egyptian artifacts and the oldest human fossil found in Brazil.

The destruction of the building, where emperors once lived, was an "incalculable loss for Brazil," President Michel Temer said in a statement.

"Two hundred years of work, research and knowledge were lost."

His office did not immediately respond to requests for comment on widespread allegations of neglect.