Gunmen who seized 52 hostages inside a Venezuelan bank ended a standoff that lasted more than 24 hours as they surrendered on a roadside after a chase, freeing their last five captives.

One of the gunmen accidentally shot himself in the leg when his gun went off during the chase, but none of the hostages was seriously hurt, said Justice Minister Ramon Rodriguez Chacin, calling it a "100 percent" success.

"This nightmare is over," Guarico state Gov. Eduardo Manuitt told state television.

The gunmen were captured less than two hours after they fled the bank in an ambulance under a deal negotiated with police.

Click here for photos.

Once the men pulled over, they first let three hostages go and then negotiated with police while holding on to the last two. They soon tossed down their guns and a grenade, and were ordered to the ground and arrested, Manuitt said.

Their capture ended an ordeal that began Monday morning with a botched bank robbery in this town southeast of Caracas. The hostage standoff at the Banco Provincial branch was the longest in at least a decade in Venezuela.

In the final hours, some hostages inside the bank held up signs in the windows with desperate pleas for help and used cell phones to call their relatives.

Under the deal with police, the gunmen were permitted to leave with five hostages who agreed to accompany them, freeing the rest at the bank. Police allowed the gunmen to flee because "they threatened to start killing the hostages in 20 minutes," Manuitt said.

One of the hostages who later left with the gunmen, Vanessa Saavedra, spoke quietly and haltingly to Colombia's Caracol Radio by cell phone from inside the bank, saying: "We don't want them to shoot ... We don't want them to open fire. Please."

Saavedra's mother, Jasmin Gonzalez, said her daughter — a 25-year-old teller — volunteered to leave with the gunmen. "She's very brave. I know she's going to come out of this fine," Gonzalez said through tears outside the bank.

A total of 52 people were taken hostage at the bank on Monday, including five who were released during the standoff and two who managed to escape, Rodriguez said. After another five left in the ambulance, 40 were left behind and freed, he said.

Other officials had earlier given lower estimates of about 30 hostages inside the bank.

Relatives and onlookers massed at the front door while the hostages were led to waiting ambulances.

Those freed included a 2-week-old infant, at least three other children under the age of 10, and a woman who is eight months pregnant. She was wheeled out reclining on a stretcher.

One man emerged with a bandaged hand, carrying a girl in his arms.

The four gunmen entered the bank Monday morning when a uniformed police officer pulled up to use the cash machine and surprised the would-be robbers, said Amanda Saldivia, a reporter for the local Guarana Radio FM.

"After five or six hours, they began to let down their guard saying, 'You aren't going to die,"' freed hostage Juan Carlos Gil told The Associated Press of his captors. "They were nervous, but it was all an atmosphere as if they were everyone's friends."

His account differed from that of the justice minister, who said the gunmen had been taking drugs, making the situation volatile.

Gil said he never saw any of the gunmen use drugs and they appeared sober.

But Saavedra said she was terrified when the men pointed a gun at a security guard and threatened him. "He went out running and they shot at him" but missed, Saavedra told Caracol. "It was truly horrific."

Every twist and turn of the hostage drama became a spectacle in TV and radio news reports in Venezuela — and in neighboring Colombia.

The radio station Caracol even contacted the gunmen, one of whom said: "I haven't eaten anything. ... I've kept myself going on sugar."

Rodriguez celebrated what he called impeccable work by police and lashed out at what he called the "yellow journalism" of some Venezuelan and Colombian media, saying they tried to use "images of terror" to create panic in the population.

He said he plans to lodge a complaint with Venezuela's broadcast regulatory agency against some media outlets. He did not elaborate.

Shortly before the kidnappers fled the bank, one of the hostages broke a window in desperation, and one of the gunmen fired a shot in response, Manuitt said.

Officials did not immediately say if the gunmen left with any money.

Police officers with assault rifles took up positions at windows directly above the bank during the standoff, and then stood down at the urging of a hostage as the ambulance pulled up to ferry the group away.

Security cameras captured images of the gunmen until the cameras went dead — apparently cut off by the men — and the footage was turned over to authorities, said Cottin, the Venezuela president of Spain's Bilbao Vizcaya Argentaria, or BBVA, which owns Banco Provincial.

As for the gunmen, Manuitt told state television, "We think they don't have much experience because of the sort of weapons they carry and by their behavior." He said they carried handguns and "a type of grenade."