A gunman holding a busload of passengers hostage in the Brazilian city of Rio de Janeiro has been shot dead by police, officials said, ending a hijacking that had lasted for several hours.

Dozens of people were trapped on the vehicle after it was taken over by the gunman on a busy bridge connecting Rio with the neighboring city of Niteroi.

At least six people - four women and two men - were freed. Around 31 people had remained on the bus throughout the ordeal.

Heavily armed police, including military and snipers, had surrounded the vehicle as they negotiated with the gunman, who it is reported had been armed with a gun, a taser and petrol.

A military police spokesman later told local media that the hijacker had been shot and died at the scene.

None of the hostages were injured.

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

The gunman reportedly boarded the Rio-bound bus at 5.30am local time (9.30am Irish time) and began threatening passengers.

He poked his head out of the bus at one point, showing his face, reports say.

Around four hours later the young man was shot dead by a sniper. His identity has not been released.

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

This is not the first time a gunman has hijacked a public transport bus in Rio. In 2000, a gunman stormed a vehicle in a fashionable neighbourhood 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.