Turkey inflicted France's only defeat of its Group H campaign so far, in June, and proved the world champion's nemesis again.
Substitute Olivier Giroud's 76th-minute header looked to have wrapped up France's qualification with two matches to spare, but it was not to be for Didier Deschamps' side.
Hakan Calhanoglu's free-kick teed up Ayhan for a close-range finish and France will now have to wait until November to claim a spot at next year's finals.
France would have capped a dominant start if not for Turkey goalkeeper Fehmi Mert Gunok, who spread himself to deny Antoine Griezmann before brilliantly keeping out Moussa Sissoko's follow up.
Sissoko – who also went close with a header early on – had another opportunity in the 24th minute as France continued to threaten, but his snapshot failed to trouble Gunok.
Griezmann soon took matters into his own hands with a wonderful, curling effort from the edge of the box, yet despite beating Gunok, his strike inched wide of the upright.
France wanted a penalty when Griezmann went down under Merih Demiral's challenge, but the referee waved play on – Burak Yilmaz blazing over at the other end after a swift Turkey counter.
Deschamps turned to Giroud in the 72nd minute and the striker swiftly justified the change, heading home Griezmann's corner at the near post.
The host could not hold on, however, as Turkey substitute Calhanoglu provided a wicked cross for Ayhan to nod in and secure a share of the spoils.