A police officer shot dead a man armed with a knife as he tried to attack a police station in the northern Spanish region of Catalonia on Monday, in what authorities are treating as a "terrorist attack".
Police said the man invoked the name of Allah during the assault, which came just days after the first anniversary of a twin attack in Catalonia that killed 16 people.
The man arrived at the closed police station in the town of Cornella de Llobregat near Barcelona at 5:45 am (0345 GMT) and repeatedly pressed the buzzer to be let in, Rafel Comes, a commissioner with the Catalan regional police, told a news conference.
After police allowed him in, the man pulled out a "large knife" and lunged at officers in "a clearly premeditated desire to kill an agent of our force," Comes said.
"The officer used her gun to save her own life," Comes said, adding the man shouted "Allah" as well as words the police officers did not understand.
"These are enough indication to treat the events being investigated as a terrorist attack."
Anti-terrorism police sources had earlier told AFP the man was a 29-year-old Algerian, but Comes said police still needed to confirm that the Algerian identity papers he carried with him were in fact his.
The police station in Cornella de Llobregat, a working-class town of around 86,000 people, was quickly cordoned off after the attack and the attacker's body removed, according to an AFP reporter at the scene.
- 'It was strange' -
Police explosives experts searched the man's flat, which was located just a few hundred metres (yards) from the site of the attack.
Resident Conchi Garcia, a 50-year-old office worker, said the man came to the neighbourhood two years ago, when he moved in with a woman and her two daughters who had always lived in the area.
"It was strange that the woman started wearing the veil shortly after he arrived," Garcia told AFP.
Security has been reinforced at police stations across Catalonia.
The incident occurred just days after the one-year anniversary of a deadly jihadist rampage in Catalonia.
Sixteen people were killed on August 17 and 18, 2017 when a van drove into crowds on Barcelona's popular Las Ramblas boulevard and in a knife attack in the nearby resort of Cambrils.
The Islamic State group claimed responsibility for the attacks, Spain's worst since the Madrid train bombings in 2004 when 191 people died and more than 1,800 were injured.
Spain has kept its terrorist alert at the second-highest level since 2015.
- 'Centre of jihadist activity' -
Catalonia, which is home to a significant number of second-generation North African immigrants, has had a long history of Islamic militant activity.
Spain's first Muslim extremist -- a member of the Algerian Armed Islamic Group (GIA) -- was uncovered in Catalonia in 1995.
Mohammed Atta, the pilot who slammed a passenger plane into one of New York's World Trade Center towers on September 11, 2001, spent time in Catalonia shortly before the attacks.
And in 2008, police foiled a plot targeting Barcelona's underground trains.
One in four people detained in Spain in relation to extremist Muslim-linked terrorism come from the Catalan province of Barcelona, according to a study published last year by the Real Instituto Elcano, a Spanish think-tank, which called the province the country's "main centre of jihadist activity".
The Islamic State group has frequently called on their followers to attack soldiers and police in neighbouring France.