A terrorist knifeman 'shouting Allahu Akbar' has been shot dead by a female cop after trying to stab officers in an attack on a police station in Barcelona today.

The 29-year-old pleaded to be let into the premises in Cornella on the outskirts of the Catalan capital just before 6am - only to lunge at officers inside with a 'large' blade.

A female police officer opened fire and 'took him' the Algerian, who lived in the area. He is said to have shouted 'Allahu akbar' (God is greatest) as he entered the station.

But police have found no evidence linking the incident to terror attacks last August in Barcelona and nearby Cambrils, which killed 16 people.

Despite the police suspicions, the Interior Ministry said it was keeping the country's terror alert at level 4, indicating high risk. Spain has been at that stage of alert since 2015, following a series of terror attacks abroad. Level 5, indicating a 'very high risk' of attacks, is the highest level.

A terrorist knifeman 'shouting Allahu Akbar' has been shot dead by a female cop after trying to stab officers in an attack on a police station in Barcelona today. Police are pictured preparing to enter the man's apartment block after the attack

Police have shot a knifeman shouting Allahu Akbar who tried to attack them at a station near Barcelona early this morning. Pictures show police near the headquarters

The drama happened around 6am at a police station in Cornella on the outskirts of the Catalan capital. Pictures have emerged showing the man's body being removed from the police station

Officers opened a locked police station security door to the man, who lived in a nearby apartment, Comes said. The police station is located in the Cornella district on the outskirts of the city.

He said the suspect repeatedly pressed the buzzer to be let in and spoke with officers inside over an intercom. After they decided to let him in, he pulled out 'a large knife' and lunged at officers, according to Comes.

The man had ID documents on him and police are checking whether they are authentic.

Comes said authorities have found no criminal record for the man identified in the documents, although international police databases are being searched for matches with his fingerprints.

'We are treating it as a terrorist attack. The officer used her gun to save her own life,' Rafel Comes, a commissioner with the Catalan regional police, told a news conference in Cornella de Llobregat where the attack took place.

The man arrived at the police station in the town near Barcelona at 5.45am with a knife and 'a clearly premeditated desire to kill an agent of our force,' he added, saying security was being reinforced at police stations across Catalonia.

Anti-terrorism police sources had earlier told AFP that the man was a 29-year-old Algerian who lived in the area, and had shouted 'Allahu akbar' (God is greatest) as he entered the station.

But Comes said the agent who shot the man dead can only recall hearing him invoking the name of 'Allah' and the rest of what he said was incomprehensible.

The commissioner would not confirm the attacker was Algerian, saying police still needed to confirm that the Algerian identity papers he carried with him were in fact his.

The police station was cordoned off and funeral home employees removed the attacker's body from the building, an AFP photographer at the scene said.

Officers searched the man's home (pictured), which was located just a few hundred metres (yards) from the site of the attack

Catalan regional police forces stand guard outside the apartment building of a man who tried to attack a police station in Cornella

The 29-year-old pleaded to be let into the premises in Cornella on the outskirts of the Catalan capital just before 6am - only to lunge at officers inside with a 'large' blade. A neighbour of the suspect is pictured being evacuated this morning

Officers searched the man's home, which was located just a few hundred yards from the site of the attack.

The incident occurred just days after the first anniversary of a deadly jihadist rampage in Catalonia.

Sixteen people were killed on August 17, 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.

ISISI 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.

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.

The incident occurred just days after the first anniversary of a deadly jihadist rampage in Catalonia

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, a plot targeting Barcelona's underground trains was foiled when it was already in advanced stages.

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'.

There have been a string of similar incidents in neighbouring France targeting police and soldiers, including one in January 2016 in which police shot dead a man wielding a cleaver and yelling 'Allahu akbar' as he tried to attack a police station in northern Paris.

That incident came on the one-year anniversary of the terrorist attack on satirical newspaper Charlie Hebdo.

ISIS has frequently called on their followers to attack soldiers and police in France, who they see as a legitimate target because they represent the French state.