OSLO — The police in Norway said on Sunday that they were investigating a foiled attack at a mosque near Oslo as an attempted act of terrorism after a white gunman in a helmet and body armor opened fire but was overpowered before injuring anyone.

They also said a young woman found dead in the suspect’s home was his 17-year-old stepsister.

Friends and former classmates of the suspect, whose name has not been released by the police but was being reported by Norwegian media, said he had taken increasingly extremist stances against immigrants and women.

The mosque attack on Saturday came amid a polarizing debate in the country about immigration and Islam, and prompted the authorities to order police officers to guard mosques in the city. Officers, who generally do not carry weapons, were armed for the rest of the weekend, the authorities said.

“I guarantee that the police are doing everything we can to keep people safe,” a police spokesman, Jan Eirik Thomassen, said at a news conference on Sunday.