The teenage gunman shouted threats and walked with the weapon before he was caught. (Reuters)

The teenage shooter who fired at protesters near Jamia Millia Islamia University in Delhi on Thursday has been charged with attempted murder, the police said today. The 17-year-old, a class 12 student from Uttar Pradesh, has also been charged under the Arms Act.

The police say he had bought the crude pistol a few days ago and had been planning to attack a protest against the citizenship law.

On Thursday morning, the teen reportedly left his house in Jewar, about 68 km from Delhi, claiming he was going to school as usual. But he took a bus to Delhi instead.

He emerged in the afternoon at the students' protest at Jamia University against the Citizenship (Amendment) Act and blended in the crowd.

Around 1.40 pm, he emerged from the crowd and pulled out a gun, shouting "Yeh lo Azaadi (here's your freedom)". Dozens of policemen in riot gear watched as he kept waving his gun at unarmed protesters and shouting threats.

When he fired a shot, metres away from the policemen, it hit a student who was apparently trying to calm him down - Shadab Farooq, a first year mass communication student.

Before his act, the teen shooter had been on Facebook livestreaming.

A policeman eventually approached him and overpowered him.

On the slow response of the police, an officer said the boy was about 30 metres away with his back to them, so the weapon was "not visible".

While being taken away, he shouted "Delhi Police zindabad (Long live Delhi Police)".

Videos on the teen's Facebook timeline showed him walking around in the crowded road - the venue of the protest - with a red backpack on. His posts seemed to indicate that he had come prepared for the consequences of his action. "On my last journey, take me draped in saffron and shout slogans of Jai Shri Ram," one of them in Hindi read.

Another more threatening post read, "Shaheen Bagh, Game Over", referring to a massive protest against the citizenship law taken up by women and children.

The incident comes against the backdrop of hate speeches made during the campaign for the February 8 Delhi election; Union Minister Anurag Thakur has been banned from campaigning for 72 hours after he was caught on camera encouraging the slogan "Desh Ke Gaddaro Ko, Goli Maaro S****n Ko (Shoot the traitors)" at a rally.

Home Minister Amit Shah has ordered stringent action in the shooting incident and said "the culprit will not be spared".

Later, hundreds more joined the protest and tried to march towards Rajghat but were stopped by the police, who had put up barricades.

Thousands, including students in multiple cities and towns across the country, have taken to the streets since last month to protest the new citizenship law that they say discriminates against the minority Muslim community.

The Citizenship (Amendment) Act, for the first time, makes religion the test of citizenship in India. The government says it will help minorities from three Muslim-dominated countries to get citizenship if they fled to India because of religious persecution. Critics say it is designed to discriminate against Muslims and violates the secular principles of the constitution.