Several people have been killed as the unrest spreads to new corners of the country, and security forces have cracked down.

Credit...Adnan Abidi/Reuters

NEW DELHI — Furious protests against a new citizenship bill continued to erupt across India on Monday, provoking a harsh security response and presenting the most widespread challenge to Prime Minister Narendra Modi since he came to power five years ago.

On Sunday, police officers stormed a predominantly Muslim university in New Delhi, the capital, firing tear gas into a library where students had sought refuge and beating up dozens.

The protests have gripped many major Indian cities and are a reaction to the Indian Parliament’s decision last week to pass a contentious measure that would give special treatment to Hindu and other non-Muslim migrants in India. Critics have called the measure blatantly discriminatory and a blow to India’s foundation as a secular democracy.

The legislation is a core piece of a Hindu-centric agenda pursued by Mr. Modi and his Bharatiya Janata Party, and many analysts predicted trouble. India’s large Muslim minority, around 200 million people, has become increasingly fearful, certain that many of Mr. Modi’s recent initiatives are intended to marginalize them.

Protests broke out last week in northeastern India, where several demonstrators were killed, and have spread to Bhopal, Jaipur, Ladakh, Kerala, Kolkata, Hyderabad and Lucknow. Cars, buses and railway stations have been set on fire in an explosion of anti-government feeling.

On Sunday, when students at Jamia Millia Islamia University, a primarily Muslim university in New Delhi, organized a large demonstration, which many witnesses said started out peacefully, the police responded with force.

Videos widely circulated on social media show officers beating students with wooden sticks, smashing some on their heads even after they had been knocked down. In one video, a group of female students tries to rescue a young man from the grasp of the police. A squad of officers in riot gear tears him away and knocks him down with heavy blows. Even after the women form a protective circle around the downed student, officers can be seen trying to jab the young man with their wooden poles.

“The police barged into the girls’ hostel, they barged into the boys’ hostel,” one young woman told reporters. “Students were running around to save their lives. Is this democracy? Where are we living?”

Dozen of students were hospitalized, some with broken bones, according to news media reports. Some witnesses said that gangs of older men appeared on campus to battle students, possibly an echo of past episodes of organized Hindu-Muslim clashes. Some students raced to seek shelter in a library where they were tear-gassed by the police.

Observers said that while police brutality was common in poorer, more rural areas of India, it was extremely unusual to see it explode on such a scale in the capital.

Lokesh Devraj, a product designer who lives near the university, said he exited a metro station on Sunday afternoon and saw a stampede of terrified university students running toward him as the police charged, sticks in hand, beating at whatever crush of people they could find. The students did not resist, Mr. Devraj said, and had no sticks or stones in their hands.

A police officer ran at Mr. Devraj and his 65-year-old father, he said, waving a baton in his clenched fist. Mr. Devraj shielded his father from the blows and was beaten himself, he said. The police officer backed off only after Mr. Devraj explained that he was simply a resident trying to return home.

India, at around 80 percent Hindu and 14 percent Muslim, has a history of convulsions of religious violence. With this citizenship measure, the Modi government has been pushing legislation guaranteed to create anger and despair in India’s minority Muslim community.

It comes against a steady drumbeat of anti-Muslim moves by Mr. Modi’s government and its allies across India’s states including: changing historic place names from Muslim names to Hindu ones; editing government-issued textbooks to remove mentions of historic Muslim rulers; and stripping away statehood from what was India’s only Muslim-majority state, Jammu and Kashmir, and indefinitely incarcerating hundreds of Muslim Kashmiris.

The new citizenship legislation, called the Citizenship Amendment Bill, expedites Indian citizenship for migrants from some of India’s neighboring countries if they are Hindu, Christian, Buddhist, Sikh, Parsee or Jain. Only one major religion in South Asia was conspicuously left off: Islam.

Indian officials have denied any anti-Muslim bias and said the measure was intended purely to help persecuted minorities migrating from India’s predominantly Muslim neighbors — namely Pakistan, Afghanistan and Bangladesh.

The legislation, which passed through both houses of Parliament and now awaits the president’s signature, which is expected, follows hand in hand with a divisive citizenship test conducted this summer in one state in northern India and possibly soon to be expanded nationwide.

All residents of the state of Assam, along the Bangladesh border, had to produce documentary proof that they or their ancestors had lived in India since 1971. Around two million of Assam’s population of 33 million — a mix of Hindus and Muslims — failed to pass the test, and these people now risk being rendered stateless. Huge new prisons are being built to incarcerate anyone determined to be an illegal immigrant.

Amit Shah, India’s powerful home minister and Mr. Modi’s right-hand man, has vowed to bring citizenship tests nationwide. A widespread belief is that the Indian government will use both these measures — the citizenship tests and the new citizenship legislation — to render millions of Muslims who have been living in India for generations stateless.

International organizations have sharply criticized the direction India is headed.

The United Nations High Commissioner for Human Rights called the new bill “fundamentally discriminatory.”

And the United States Commission on International Religious Freedom, a federal body, called the measure a “dangerous turn in the wrong direction” and said that the United States should consider sanctions against India if the bill passes.

Maria Abi-Habib contributed from New Delhi.