The leader of Turkey’s main opposition party has been attacked at the funeral of a soldier killed in fighting against Kurdish militants. The Republican People’s party (CHP) leader, Kemal Kılıçdaroğlu, was taken to a nearby house by security forces for his protection, the state news agency Anadolu said.

Video of the incident on social media showed a mob pushing and shoving Kılıçdaroğlu as he made his way through the crowd. His party confirmed that Kılıçdaroğlu had been attacked but said he was safe. “Kılıçdaroğlu is at the CHP headquarters right now. He is fine,” a party official said.

In a speech later outside his party’s HQ, Kılıçdaroğlu said the attack targeted Turkey’s unity. “The assailants have no respect for the martyr [dead soldier],” Kılıçdaroğlu told a crowd of around 1,000 supporters from the top of a bus. “They are not genuine Muslims,” he said. He said the incident would not deter him from defending law and justice.

The Ankara governor’s office said in a statement: “Legal action has been launched against the culprits of the incident.”

The CHP last month won mayors’ offices in Ankara and Istanbul in local elections in a setback for the ruling party of the president, Recep Tayyip Erdoğan. Erdoğan’s Justice and Development party (AKP) is appealing for a rerun of the Istanbul election citing irregularities in the tight race against the CHP candidate, Ekrem İmamoğlu.

Election authorities last week granted İmamoğlu his mandate after carrying out a limited recount that showed he had won the city by a slim margin of about 13,000 votes.

The soldier had died in clashes with the outlawed Kurdistan Workers Party (PKK). However, Erdoğan had repeatedly warned that PKK members were among the CHP’s list of candidates.

PKK clashes with Turkish soldiers in the country’s south-east on Friday prompted several pro-government newspapers to tie the soldiers’ deaths to the CHP. “PKK out” was among the slogans shouted at Kılıçdaroğlu on Sunday, according to video footage of the incident.