After trying to comfort the girl by kissing her on both cheeks, Erdogan told the crowd: "She has the Turkish flag in her pocket. If she becomes a martyr, God willing, this flag will be draped on her." Some people were appalled and took to Twitter to criticise the president.
One user said it was the state's duty to protect children, not to "kill" them. Another said: "you don't wish death for a child, you never say: 'God willing.'"
His action comes as nationalist sentiment is running high over a Turkish cross-border military offensive against Syrian Kurdish fighters that are affiliated with Kurdish rebels fighting inside Turkey.
In recent weeks, children dressed in commando uniforms or reciting nationalist poems have been making appearances in many events that he attends.
Yasar Okutan, a former government minister, accused Erdogan in a television interview of using them to increase votes in presidential and local elections in 2019 and questioned whether the president would say the same for his own granddaughter.