(CNN) -- Inmates at the Rodeo II prison in Venezuela -- who had been in a 27-day standoff with the national guard -- Wednesday abandoned the building and turned themselves over to authorities, according to Venezuelan Interior and Justice Minister Tarek El Aissami.
In all, 1,019 inmates were evacuated from the prison, officials said.
Troops and prisoners had been in a standoff since last month, when the government ordered raids at the Rodeo prison complex to regain control and disarm inmates.
The government claimed that a small group of prisoners at the Rodeo II prison -- about 50 out of 1,000 -- were hostile to the national guard and gave resistance to any raid, basically keeping the other inmates captive. Authorities successfully raided the neighboring Rodeo I prison, where they seized dozens of weapons, as well as drugs and cell phones.
El Aissami said the end to the standoff was the result of dialogue and mediation between the two sides, and he accused political opponents of hoping for a more chaotic ending.
"It is dialogue that triumphed," he said, adding that the human rights of all the inmates were being protected.
The inmates received medical attention as they left, including hydration, officials said, before being moved to another prison.
Black smoke could be seen coming from the Rodeo II tower, presumably as inmates burned their belongings before abandoning the building. Some gunfire was also heard.
One of the inmate leaders behind the standoff, identified as Yoifre Ruiz, 20, was in custody, the state-run broadcaster VTV reported. A second leader, and Yorvis Lopez, 26, escaped and was being sought by authorities.
Renovations at the prison would begin immediately, El Aissami said.
Journalist Osmary Hernandez contributed to this report for CNN.