ARTICLE AD BOX
By Vanessa Buschschlüter
BBC News
The top national security advisor to Brazilian President Luiz Inácio Lula da Silva has resigned after video emerged showing the aide inside the presidential palace in Brasilia during rioting on 8 January.
Gen Marcos Gonçalves Dias stepped down after CNN Brasil broadcast CCTV footage of him talking to members of a mob which had stormed the palace.
The general denied accusations that he had facilitated the rioters' entry.
He said he arrived after the rioters.
CNN Brasil said it had analysed 160 hours of footage from 22 separate cameras.
In its report, the broadcaster showed footage of Gen Gonçalves Dias in the same corridor as some of the people who had stormed the building.
CNN says the footage was recorded in the corridor outside a room leading to the office of the president on the third floor of the palace.
The images appear to show the general pointing out the emergency exit to the rioters. There is no sound, so it is not clear what he says to them.
The general told Brazilian TV channel GloboNews that he "was removing people from the third and fourth floors so that they could be arrested on the second floor".
Gen Gonçalves Dias argued that his actions had prevented the ransacking of the third and fourth floor of the palace.
He added that he had handed in his resignation so the investigation into the riots could proceed "in a transparent way".
Other footage broadcast by CNN appears to show members of the Institutional Security Bureau (GSI), which Gen Gonçalves Dias leads, handing out bottles of water to some of the rioters and shaking hands with them.
Gen Gonçalves Dias said those shown handing water to the rioters had been removed from their posts and were currently under investigation.
The presidential palace was one of three buildings in Brasilia which rioters opposed to the election of President Lula stormed on 8 January.
Opponents of the newly elected president had been camping out in front of army barracks across the country in an attempt at convincing the army to prevent the transfer of power from the outgoing far-right president, Jair Bolsonaro, to Lula.
With their frustration growing after Lula's swearing-in on 1 January, they began to congregate in the capital.
On 8 January, they rampaged through the presidential palace as well as Congress and the Supreme Court, breaking windows and furniture as well valuables, such as a 17th-Century French clock. They caused millions of dollars of damage.
Security forces eventually regained control of the situation and detained around 1,500 people.
But the security forces came under heavy criticism for not preventing the rioters from entering these key buildings.
The chief of security for the capital at the time of the attack, Anderson Torres, is in jail awaiting trial on charges of sabotaging efforts to protect the buildings.
President Lula's predecessor in office, Jair Bolsonaro, is due to testify within the coming days over his alleged role in inciting the rioters.
Prosecutors say he fanned the flames by questioning the legitimacy of the election result, which saw him narrowly lose to Lula.