Erdogan mercilessly mocked Ekmeleddin Ihsanoglu for not knowing the Istiklal Marsi (Independence March) anthem, a huge insult in a country which sets great store by patriotism.
Ihsanoglu, a softly-spoken, bespectacled intellectual, had visited a cemetery in Istanbul while campaigning and stopped by the tomb of poet Mehmet Akif Ersoy, the author of the words to the anthem.
The 70-year-old, a former head of the Organisation of the Islamic Cooperation (OIC), boasted that Ersoy was a friend of his father in the early 1900s when the Turkish republic was founded.
Speaking at a mass rally in the city of Kahramanmaras in southeastern Turkey today, Erdogan broke off from his speech to air a video of Ihsanoglu's faux pas on a big screen.
Also Read
Erdogan accused Ihsanoglu of being "incapable of making a distinction between the national anthem and a Gallipoli poem."
He slammed Ihsanoglu as an "imported candidate... Unable to recognise the national anthem."
Ihsanoglu, who speaks five languages, is a scholar with a long diplomatic career who makes no secret of his devotion to Islam and learning.
But the episode is potentially damaging to Ihsanoglu, who has already had to defend his patriotism as he was born in Egypt where his cleric father was living in exile.
In an unusually angry reaction, Ihsanoglu today hit out at Erdogan's remarks as a "lie" and a "slander".
"I am the son of the closest friend to Mehmet Akif (Ersoy). You must be kidding me. I learnt it while sucking my mother's milk before you did," he said, referring to Erdogan.
"Can someone who does not know his national anthem be a president? He could not even pass his class," wrote a Twitter user ilhanbozkurt78.