ANKARA (Reuters) - 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.

Erdogan, who is seeking to rally support for his Islamist-rooted AK Party in March 31 local elections, has invoked the New Zealand attack as evidence of global anti-Muslim sentiment.

"They are testing us from 16,500 km away, from New Zealand, with the messages they are giving from there. This isn't an individual act, this is organized," he said, without elaborating.

Australian Brenton Tarrant, 28, a suspected white supremacist, was charged with murder on Saturday after a lone gunman killed 50 people at mosques in the city of Christchurch.

At weekend election rallies 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.

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 himself, 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 1,000 years and will be here until the apocalypse, God willing," 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."

Story continues

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 Minister Winston Peters said he told his Turkish counterpart that 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," 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 Tarrant 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.

(Reporting by Tuvan Gumrukcu; Editing by Dominic Evans and Nick Tattersall)