Protesters have assaulted the leader of Turkey’s main opposition party during a funeral held for a soldier who was killed during clashes with Kurdish rebels.

The politician was not hurt, party officials said.

People threw punches at Republican People’s Party leader Kemal Kilicdaroglu as security officials tried to escort him away from Sunday’s funeral in a village outside of Ankara, television footage showed.

Turkey Opposition Leader
Security officials try to stop protesters attacking Kemal Kilicdaroglu (DHA/AP)

An angry crowd then surrounded a house where he was taken for safety.

Mr Kilicdaroglu was later driven out of the village in an armoured vehicle.

Turkey Opposition Leader
Kemal Kilicdaroglu, the leader of Turkey’s main opposition Republican People’s Party, leaves after being attacked by protesters (AP)

The soldier was among four killed Saturday in a clash against the rebels of the outlawed Kurdistan Workers’ Party rebels, or PKK, near Turkey’s border with Iraq.

The group is considered a terror organisation by Turkey, the United States and the European Union.

The Ankara governor’s office said legal action had been launched against the assailants.

Turkey Opposition Leader
Kemal Kilicdaroglu, the leader of Turkey’s main opposition Republican People’s Party, CHP, addresses CHP members (Burhan Ozbilici/AP)

Mr Kilicdaroglu’s pro-secular Republican People’s Party, or CHP, won control of Ankara and Istanbul during local elections on March 31.

Turkish President Recep Tayyip Erdogan’s ruling party previously governed in the two cities.

Mr Erdogan led the Justice and Development party’s divisive election campaign, portraying the local races as a matter of national survival and equating opposition parties with terrorists.

The funeral assault cast a shadow on a rally organised in Istanbul to celebrate the CHP mayoral candidate’s win, which ended the ruling party’s and its Islamist predecessor’s 25-year hold on the city of 15 million.

Turkey Opposition Leader
Bodyguards protect Kemal Kilicdaroglu (DHA via AP Photo)

The ruling party is now seeking a rerun of the election, claiming widespread irregularities.

Turkey’s top electoral body is considering the ruling party’s appeal.

Ekrem Imamoglu, 48, was confirmed as mayor on Wednesday following two weeks of appeals and recounts requested by the ruling party.

He has taken a conciliatory tone, promising to bring people together following the polarising elections.