Police at the site where candidate for the mayor of Cologne Henriette Reker was wounded in a stabbing (Federico Gambarini/dpa via AP)

Independent candidate for the mayor of Cologne Henriette Reker was stabbed while out campaigning (Oliver Berg/dpa via AP)

A candidate who was stabbed as she campaigned by a man who said he acted out of anti-foreigner motives has been elected as mayor of Cologne, Germany's fourth-largest city.

Henriette Reker won 52.7% of the vote, final results showed. Ms Reker, who is currently responsible for housing refugees in Cologne, ran as an independent but was backed by Chancellor Angela Merkel's conservative Christian Democrats and two other parties.

Ms Reker was stabbed in the neck and seriously wounded Saturday by a 44-year-old German man. A psychological examination showed that there is no reason to doubt he can be held criminally responsible, prosecutors and police said.

The suspect, who has not been identified, was ordered kept in custody on suspicion of attempted murder and dangerous bodily harm.

The man has told officials, without giving details, that he was actively involved in the far-right scene in the past, prosecutors and police said in a joint statement.

"This time goes back to the '90s," the statement said. "In what function and intensity" he was involved is now a matter for investigation.

Officials have said that the man apparently acted alone and had no police record.

Germany's interior minister has said that the attack on Ms Reker underlines growing concerns over hatred and violence amid the refugee crisis.

Doctors say an operation on Saturday went well and Ms Reker's life is not in danger. They say she is expected to make a complete recovery.

Ms Reker, 58, had been one of the pre-election favourites to win. She handily beat the other main candidate in a seven-strong field, centre-left Social Democrat Jochen Ott, who polled 32%.