A military police spokesman said the man turned out to be carrying a toy gun.(AFP)

A hijacker armed with what turned out to be a toy gun was shot dead by police in Rio de Janeiro on Tuesday after he held a busload of passengers hostage for several hours on a major bridge in peak-hour traffic.

Dozens of people were trapped on the public bus on a heavily transited bridge connecting Rio with the neighboring city of Niteroi after it was commandeered by the man, who also carried gasoline.

Around 31 people were stuck on the vehicle throughout the terrifying, four-hour ordeal, but no one was hurt, police said.

At least six others -- four women and two men -- were freed.

A military police spokesman said the man turned out to be carrying a toy gun.

"It was necessary for the sniper to neutralize (the hijacker) and save people on the bus.

"He (hijacker) died at the scene."

Heavily armed police including military and snipers had surrounded the bus as they negotiated with the hijacker, whose identity has not been released.

A live broadcast of the scene showed several ambulances parked near the bus, receiving hostages as they were released one by one.

The man reportedly boarded the Rio-bound bus at 5:30 am (0830 GMT) and began threatening passengers.

"He said the bus was being hijacked and didn't ask for our belongings," Hans Moreno, one of the passengers, told Globo TV.

"He was very calm, very quiet."

Walter Freire, another passenger, said he thought he was "going to die."

"Thank God the police performed well," Freire told Globo TV.

Several lanes of traffic on the busy Rio-Niteroi bridge spanning Guanabara Bay were paralyzed during the hostage situation.

Commuters stopped on the bridge could be seen standing outside their cars and taking photos or filming videos with their smartphones.

The bus had been on its way to Rio, a sprawling city of more than six million people where deadly violence is common.

"Ideally everyone would have got out of this alive, but we had to take a decision to save the hostages," Rio state Governor Wilson Witzel told reporters at the scene.

"We are looking after the families of the hostages and of the person who died."

A member of the hijacker's family had "apologized to the entire society," Witzel added.

The hijacker -- a young man wearing a white T-shirt and dark-colored trousers -- exited the bus at one point, showing his face, G1 reported.

It is not clear if he made any demands or what his motivation was for taking the hostages.

"We ask the population to stay calm. Our police are at the scene," military police tweeted during the standoff.

This is not the first time a public transit bus has been hijacked in Rio.

In 2000, a gunman stormed a passenger bus in a fashionable neighborhood of the city. The hours-long hijacking of bus 174 was later turned into an award-winning documentary.

The hijacker and one hostage were killed in that incident.