Portuguese police accused an Afghan refugee of stabbing two women to death on Tuesday at an Islamic centre in Lisbon before being shot by officers in what authorities called an "isolated" incident.
Officers were called to the centre just before 11:00 am (1000 GMT) where they encountered a man "armed with a large knife", a police statement said.
Officers ordered the man to surrender but he disobeyed and advanced towards the officers "knife in hand," it added.
"Faced with the serious and ongoing threat, the policemen used firearms against the person, hitting and neutralising the aggressor", the statement said of the man who was taken to hospital for treatment.
Interior Minister Jose Luis Carneiro said two female employees of the centre were killed in the attack at the Ismaili Muslim centre, and a man was seriously injured.
"The Ismaili Muslim community, known for its principles of humanity, peace and mutual aid, is in mourning and shocked by these tragic events," Faizal Ali, a community leader, told journalists in a brief statement.
The attacker is an Afghan who had lost his wife "in difficult circumstances" at a refugee camp in Greece before relocating to Portugal with his three children aged four, seven and nine, Carneiro added.
"There is every reason to believe that this was an isolated act. The circumstances and motives of this act are being investigated by police," he told reporters.
The attacker had not been under police surveillance and seemed to lead "a fairly quiet life" in Portugal, the minister said.
Armed police wearing bullet-proof vests stood outside the entrance to the Ismaili Muslim centre located in a landscaped park in northern Lisbon.
Police urged the public to avoid the area.
Portuguese media said the attacker frequently visited the centre to pick up donated food and study Portuguese.
The victims were the attacker's 40-year-old teacher at the centre and a 20-year-old fellow classmate, the reports said.
At the time of the attack, classes and "other activities which normally take place at the centre were underway," said the head of Portugal's Ismaili community, Rahim Firozali.
"The motives of the attacker are not known," he added in a statement.
The attacker was taken to hospital where he was under police guard, officials said.
He had moved to Portugal "a year or so ago," the president of the Afghan community Association, Omed Taeri, told CNN Portugal.
"This person lost his wife in Greece and suffers from psychological problems due to this situation," Taeri said.
"He was also concerned about his work situation and where to leave his children after finding a job."
Prime Minister Antonio Costa said it was "premature to make any interpretation of this criminal act."
"Everything points to this being an isolated incident," the premier told reporters shortly after the attack.
The Shia Imami Ismaili Muslims, generally known as the Ismailis, belong to the Shia branch of Islam, according to their website.
The Ismaili Muslims are a "culturally diverse community" of around 15 million people living in over 25 countries around the world, it says.
In recent years, particularly in Pakistan, attacks have multiplied against Ismailis who are accused by Sunni extremists of embodying a "deviant" trend in relation to Muslim orthodoxy.
Prince Karim Aga Khan, spiritual leader of the world's Ismailis, opened the Lisbon centre in 1998, a year before he obtained Portuguese citizenship.
In 2015, he established the global headquarters of Ismailism in Lisbon under an agreement with the Portuguese government.
The building, which is decorated with hand-painted tiles, has exhibition spaces, classrooms and prayer halls.
There are around 8,000 Ismaili Muslims living in Portugal, a nation of around 10 million people.
Many fled to Portugal from Mozambique, a former Portuguese colony during the African country's civil war which ended in 1992.
Religious violence is rare in Portugal and the country has not had a significant mass attack in decades.
The last major attack happened in July 1983 when five Armenian extremists died in a suicide attack on the Turkish embassy in Lisbon which killed two people.