Bangladesh rescue workers have freed a woman trapped for 17 days in the rubble of a collapsed building.

The rescuers discovered the woman Friday afternoon and ordered an immediate halt to their salvage operation. They used handsaws to cut her out of the rubble and the crowd gathered at the scene erupted in cheers.

The woman, wearing a violet dress, was rushed to the hospital in an ambulance.

Officials said 1,021 bodies have been recovered from the rubble of the fallen factory building as of Friday morning. There was no sign of where the toll might finally settle as more bodies were being found, but it is already the world's deadliest garment industry disaster and one of the worst industrial accidents.

The disaster has raised alarm about the often deadly working conditions in Bangladesh's $20 billion garment industry, which provides clothing for major retailers around the globe.

Unlike the collapse at the Rana Plaza building, which was blamed on shoddy construction and disregard for safety regulations, the fire at the Tung Hai Sweater factory appeared to have conformed to building codes. A top fire official said the deaths in Wednesday night's fire -- including a senior police officer, a Bangladeshi politician and a top clothing industry official -- were caused by panic and bad luck.

"They are really unfortunate," Mamun Mahmud, deputy director of the fire service, said Thursday.

The fire engulfed the lower floors of the 11-story factory, which had closed for the day. The smoldering acrylic products produced immense amounts of smoke and poison gas and the victims suffocated as they ran down the stairs, Mahmud said.

The building appeared on first inspection to have been properly built, though fire inspectors would conduct further checks, he said. It had two stairwells in the front and an emergency exit in the back, he said. Those inside probably panicked when they saw smoke and ran into one of the front stairwells, he said. Had they used the emergency stairwell, they would have survived, he said.

"Apparently they tried to flee the building through the stairwell in fear that the fire had engulfed the whole building," he said.

They also would have likely survived the slow-spreading fire had they stayed on the upper floors, he said.

"We found the roof open, but we did not find there anybody after the fire broke out. We recovered all of them on the stairwell on the ninth floor," he said.

The dead included the factory's managing director, Mahbubur Rahman, who was also on the board of directors of the powerful Bangladesh Garment Manufacturers and Exporters Association. Along with him was senior police official Z.A. Morshed and Sohel Mostafa Swapan, head of a local branch of the ruling party's youth league.

Independent TV, a local station, reported that Rahman had plans to contest next year's parliamentary elections as a candidate for the ruling party and had been meeting friends to discuss his future when the fire broke out.

It was not immediately clear what caused the fire, which began soon after the factory workers went home for the day and took three hours to bring under control. Mahmud speculated it might have originated in the factory's ironing section. Officials originally said the building also housed several floors of apartments, but later said it was just a factory.

The Facebook page of the Tung Hai Group claimed it was a sprawling enterprise with a total of 7,000 employees at its two factories and the capacity to produce well over 6 million sweaters, shirts, pants and pajamas every month. The group claimed it did business with major retailers in Europe and North America.

The country's powerful garment industry has been plagued by a series of disasters in recent months, including a November fire at the Tazreen factory that killed 112 and the building collapse.

More than two weeks after the building in the suburb of Savar collapsed, workers with cranes and other heavy equipment were still pulling apart the rubble and finding more bodies. On Friday, authorities said the death toll had risen to 1,021 and it was unclear how many more people remained missing. More than 2,500 people were rescued alive after the April 24 accident.

Maj. Ohiduzzaman, an army official who uses only one name, said 100 decomposing bodies have been kept at a makeshift morgue at a school and were to be sent to hospitals in Dhaka for DNA testing to identify them.

A total of 648 bodies have so far been handed over to the families, he said. Some of those who authorities have been unable to identify have been buried by the government.

Bangladeshi Nobel Peace Prize laureate Muhammad Yunus said in an article published in Bangladeshi newspapers Thursday that the tragedy was a "symbol of our failure as a nation."

"The crack in Rana Plaza that caused the collapse of the building has only shown us that if we don't face up to the cracks in our state systems, we as a nation will get lost in the debris of the collapse," he said, urging the government and citizens to work together for reforms.

He also urged global brands not to abandon the country, saying that the workers in the factories -- which often subcontract from the well-known brands -- should be seen as de facto employees of those companies.

The European Union's delegation to Bangladesh urged the government Wednesday to "act immediately" to improve working conditions in the country's garment industry.

Abdul Latif Siddiqui, head of special Cabinet committee to inspect garment factories that was formed days after the Rana Plaza collapse, said the government has closed 18 garment factories in recent days for failing to meet work and safety standards. He did not say whether the closures were temporary or permanent.

Officials say the owner of Rana Plaza illegally added three floors and allowed the garment factories to install heavy machines and generators, even though the structure was not designed to support such equipment.

The owner and eight other people, including the owners of the garment factories, have been detained.