President Tayyip Erdogan on Monday described a mass shooting which killed 50 people at two New Zealand mosques as part of a wider attack on Turkey and threatened to send back "in caskets" anyone who tried to take the battle to Istanbul.
Mr Erdogan, who is seeking to rally support for his AK Party in the 31 March local elections has invoked the New Zealand attack as evidence of global anti-Muslim sentiment.
"They are testing us from 16,500km away, from New Zealand, with the messages they are giving from there. This isn't an individual act, this is organised," he said.
Australian man Brenton Tarrant, 28, was charged with murder on Saturday after a lone gunman killed 50 people at mosques in Christchurch.
At weekend election rallies Mr Erdogan showed video footage of the shootings, which the gunman had broadcast on Facebook, earning a rebuke from New Zealand's foreign minister who said it could endanger New Zealanders abroad.
Mr Erdogan also displayed extracts from a "manifesto" posted online by the attacker and later taken down.
He has said the gunman issued threats against Turkey and the president, and wanted to drive Turks from Turkey's northwestern, European region.
Majority Muslim Turkey's largest city, Istanbul, is split between an Asian part east of the Bosphorus, and a European half to the west.
"We have been here for 1000 years and will be here until the apocalypse, God willing," Mr Erdogan told a rally on Monday commemorating the 1915 Gallipoli campaign, when Ottoman soldiers defeated British-led forces including Australian and New Zealand troops trying to seize the peninsula, a gateway to Istanbul.
"You will not turn Istanbul into Constantinople," he added, referring to the city's name under its Christian Byzantine rulers before it was conquered by Muslim Ottomans in 1453.
"Your grandparents came here ... and they returned in caskets," he said.
"Have no doubt we will send you back like your grandfathers."
Mr Erdogan was re-elected last year with new powers but his AK Party, which has ruled Turkey since 2002, is battling for votes as the economy tips into recession after years of strong growth.
He has cast the local elections as a "matter of survival" in the face of threats including Kurdish militants and attacks on Muslims such as the New Zealand shootings.
Speaking after a meeting of New Zealand's cabinet, Foreign Affairs Minister Winston Peters said he told his Turkish counterpart that Mr Erdogan's use of the footage in an election campaign was wrong.
"Anything of that nature that misrepresents this country, given that this was a non-New Zealand citizen, imperils the future and safety of the New Zealand people and our people abroad, and that is totally unfair," Mr Peters said.
Turkish relations with New Zealand have generally been good, strengthened by Gallipoli commemorations which emphasize shared sacrifices in battle as much as the confrontation itself.
Turkish Foreign Minister Mevlut Cavusoglu, who was in Christchurch and visited Turkish citizens wounded in the attack, said Muslims around the world were worried about Islamophobia and racism.
A senior Turkish security source said the accused Christchurch gunman had entered Turkey twice in 2016 - for a week in March and for more than a month in September. Turkish authorities have begun investigating everything from hotel records to camera footage to try to ascertain the reason for his visits, the source said.