The popular liberal mayor of Poland’s port city of Gdansk has died after being stabbed at a charity event by an ex-convict with a history of violent crime.

The killing plunged the politically divided country into shock and grief and brought Poles into the streets for solemn vigils in a rare show of national unity.

Pawel Adamowicz, 53, died from the wounds inflicted by a 27-year-old man who stormed onstage on Sunday evening while the mayor was addressing an audience during the Lights to Heaven, the finale of a nationwide fundraiser for sick children.

Mr Adamowicz had just expressed gratitude to the “generous” crowd, adding: “This is a wonderful time of sharing good things. You are dear. Gdansk is the most wonderful city in the world. Thank you!”

The assailant rushed up and stabbed him three times, then grabbed a microphone to tell the audience that he acted in revenge against the country’s main opposition party, Civic Platform, which Mr Adamowicz was a member of for many years but left in 2015.

With the music still playing and pyrotechnics erupting onstage, the attacker told the stunned crowd he had been wrongly imprisoned under a Civic Platform-led government.

“I was jailed but innocent. Civic Platform tortured me. That’s why Adamowicz just died,” he said.

The mayor was taken to hospital where doctors struggled to save him, but a five-hour operation and blood transfusions were not enough.

Pawel Adamowicz addresses a rally
Pawel Adamowicz addresses a rally (Wojciech Strozyk/AP)

The assassination came with the nation torn by bitter political divisions that are similar to those in the US.

The right-wing ruling Law and Justice party faced accusations that a hostile atmosphere against Mr Adamowicz and other liberals has created fertile ground for violence.

Government officials pushed back, strongly denouncing the attack and stressing the assailant had a history of violent bank robberies.

Identified by authorities only as Stefan W, he was arrested and charged with murder.

Deputy chief prosecutor Krzysztof Sierak said there were questions about the mental state of the attacker, who used a 5.5in knife, and that two psychiatrists will examine him.

He had served more than five years in prison and was released towards the end of last year.

President Andrzej Duda, who is aligned with the ruling party, opened a news conference with a minute of silence and said a day of national mourning will be observed when Mr Adamowicz’s family holds his funeral. He is survived by his wife and two daughters.

Mr Duda called him a “truly great human being, a great politician and great resident of Gdansk”, and denounced the attack as an act of unimaginable evil.

Ruling party leader Jaroslaw Kaczynski, Poland’s most powerful politician, expressed his “great pain” and solidarity with Mr Adamowicz’s family.

People place candles as they mourn Pawel Adamowicz in Gdansk
People place candles as they mourn Pawel Adamowicz in Gdansk (Wojciech Strozyk/AP)

In the evening, vigils were held in Gdansk, Warsaw and other cities. Many carried candles in glass jars and some used phones to produce flickers of light, an apparent reference to the Lights to Heaven event.

Donald Tusk, a founder of Civic Platform who was prime minister when the attacker was imprisoned and who is now president of the European Council, joined mourners in Gdansk, also his home town.

“I want to promise you today, dear Pawel, that for you and for all of us, we will defend our Gdansk, our Poland and our Europe from hatred and contempt,” Mr Tusk told the crowd.

The city flag was lowered to half-mast and masses were held in Gdansk, Warsaw and elsewhere.

Mr Adamowicz was part of the democratic opposition formed in Gdansk under the leadership of Lech Walesa during the 1980s. After leaving Civic Platform, he was re-elected to a sixth term as an independent candidate in the autumn.

As mayor, he was a progressive voice, promoting sex education in schools and tolerance for LGBT people and minorities.

He showed solidarity with the Jewish community when the Gdansk synagogue had its windows broken last year, strongly denouncing the vandalism.

He also advocated bringing wounded Syrian children to Gdansk for medical treatment, but the plan was blocked by the Law and Justice government.

After he took that stand, a far-right group, the All-Polish Youth, issued what they called a “political death notice” for him.

Government critics said they believed the violence could be partly traced to the animosity voiced against Mr Adamowicz by some ruling party officials, which at times was carried on state TV, as well as by extremists from other groups.