RIO DE JANEIRO — An armed man who took dozens of hostages on a bus in Brazil was shot dead by police following a four-hour standoff on Tuesday, authorities said.

All the hostages were freed unharmed during the incident in Rio de Janeiro, state Gov. Wilson Witzel said. The man, holding a gun and a knife, took 37 people hostage around 5:30 a.m. on a busy bridge linking the suburb of Sao Gonçalo to downtown Rio de Janeiro.

Some passengers who were earlier freed by the assailant told police that the man had spilled gasoline in the bus and was threatening to set it on fire.

However, Hans Moreno, one of the hostages, said on TV Globo that the man had appeared "very calm."

Officials said the man had identified himself as a policeman but that they were not able to confirm this information. He did not make any particular demands, according to police.

"I want to thank the police for its work," Witzel told TV Globo. This kind of situation "is happening in communities. They have rifles in the communities, terrorizing the communities."

Rio's elite police force, known as BOPE, had taken charge of negotiations with the hostage-taker. A sniper was placed nearby. Traffic was blocked in both directions on the bridge, with hundreds of vehicles waiting in line.

Sao Gonçalo, an area struggling with poverty and violence, is separated from Rio by Guanabara Bay. Many use the bridge where the hostages were seized to go to and from work.