A gunman opened fire inside a Mexico City subway station during rush hour on Friday, killing at least two people before he was subdued by the police.

Pedro Estrada, of the Mexico City Public Safety Department, said a passenger and police officer were killed at the Balderas subway station. Five others were wounded.

Luis Felipe Hernandez Castillo, 38, was arrested carrying a .38-caliber revolver, according to Mexico City’s attorney general.

The gunman was writing on the station walls with a black marker when a police officer confronted him, Attorney General Miguel Angel Mancera said.

He fatally shot the officer and a civilian who tried to stop him, Mr. Mancera said, and then ran to a subway car where he kept shooting until police subdued and captured him.

“He was out of his mind,” the attorney general said.

Witnesses told radio station Formato 21 the gunman began shooting while yelling that the attack was against the government.

One witness, Mauricio Perez, said a subway had just arrived when gunfire broke out.

“The shooting began right after the train got to the station ... this man began yelling ‘I have nothing against you, this is against the government,”’ Mr. Perez said.

The Mexican government is locked in a bloody conflict with feuding drug cartels. Unrelated shooting rampages are relatively rare in Mexico.

Millions of commuters ride the capital city’s Metro each day. Balderas station is a major transfer point between subway lines.

Keywords: MexicosubwayShootingtwokilled

More In: International | News