The mayor of the Polish city of Gdansk has died after being stabbed by a knife-wielding attacker in front of hundreds of people at a charity event.

Video footage showed the assailant bursting onto the podium and attacked Pawel Adamowicz, who had been waving sparklers on stage along with others at the fundraiser on Sunday evening.

After knifing the 53-year-old mayor several times, the man turned to the crowd with his arms raised triumphantly. He was quickly apprehended by security guards and arrested.

Paramedics resuscitated Adamowicz at the scene before rushing him to the hospital, where he later died.

Initially, doctors had said there was a slim chance Adamowicz would survive.

"He is in a critical condition ... we are battling to save him," the director of the hospital in Gdansk where the mayor was taken, Jakub Kraszewski, told reporters just before midnight local time.

A Gdansk police spokesperson said the 27-year-old attacker lived in the port city.

In a video recording of the attack posted on YouTube, the suspect was seen seizing the microphone and claiming he had been wrongly jailed by the previous centrist government of the Civic Platform and tortured.

"That's why Adamowicz dies," he said before being knocked down to the ground by security.

One witness told broadcaster TVN that the man appeared "happy with what he had done".

Convicted criminal

Adamowicz was mayor of Gdansk, a city with about half a million people, for two decades and the Civic Platform had supported his re-election in 2018 municipal elections.

His policies were considered liberal in the relatively conservative country, with Adamowicz regularly defending both the rights of LGBTQ people and refugees.

He was also part of Lech Walesa's worker uprising against communism in the 1980's, which originated in Gdansk.

Sunday's Lights to Heaven fundraiser, which was organised by the Great Orchestra of Christmas Charity, the country's most important charity, was part of a national drive to raise funds for the purchase of medical equipment and featured a colourful stage set-up, including lights, smoke and pyrotechnics.

According to Polish media, the suspect had been sentenced to more than five years in prison for four armed attacks on banks in Gdansk. His mental state had severely deteriorated during his time in jail, reports said.

Police were investigating how the attacker breached security to reach the podium, Gdansk police spokeswoman Joanna Kowalik-Kosinska told reporters.

"We know that he used an identifier with the inscription 'Press'," she said. "Now we have to establish how was it obtained, was the accreditation in his name and was he really entitled to be there at that time."

Polish Prime Minister Mateusz Morawiecki condemned the attack on Twitter and Interior Minister Joachim Brudzinski called it "an incomprehensible act of barbarism".

European President Donald Tusk, who belongs to the same political party as Adamowicz, called Adamowicz a friend on Facebook, adding "may he rest in peace".