NEW DELHI — A mob of thousands stormed a jail in the northeastern Indian city of Dimapur, seized a prisoner accused of rape, paraded him through the streets and beat him to death before they could be stopped by police gunfire, a police official said on Friday.

The dead man, identified by the authorities as Syed Sirf Khan, was accused by locals of being an illegal migrant from Bangladesh and had been arrested on Feb. 24 on suspicion of raping a woman from a Naga tribal community the day before.

How the mob was able to overcome armed police officers on Thursday at the jail in Dimapur, the commercial hub of Nagaland State, was not clear on Friday. The top police official in Nagaland, L. L. Doungel, said that because there were a number of students wearing uniforms in the crowd, the police did not want to resort to violence.

“There would have been a lot of casualties,” Mr. Doungel said. “That was one reason. The mob was in the thousands.”