Erdogan did not mention his foe by name, but he has in the past used the "cave" reference for his former ally-turned-nemesis, US-based cleric Fethullah Gulen, whose movement has many followers in the Turkish police and judiciary.
The premier last week banned Twitter, sparking international condemnation, after the micro-blogging service was used to spread a spate of other audio files implicating Erdogan and his inner circle in corruption.
An Ankara court Wednesday overturned that ruling as a limit on free speech. Turkey's telecommunications regulator TIB has 30 days to appeal the decision, and Twitter has yet to be restored, although the ban has been widely circumvented.
- YouTube 'national security threat' -
NATO-member Turkey's European and American allies condemned the YouTube ban.
"This is another desperate and depressing move in Turkey," tweeted European Commission Vice President Neelie Kroes.
Deputy State Department spokeswoman Marie Harf said the US had been "very strongly saying (to Turkish officials) that they need to stop doing this".
Thursday's YouTube leak is the first to focus on national security. Foreign Minister Ahmet Davutoglu labelled it "a declaration of war against the Turkish state and nation", while his ministry said some sections had been distorted.
TIB said it was blocking YouTube on the grounds of a "primary threat against national security," private NTV television reported.
- 'Justification can be fabricated' -
The audio recording, which could not be independently verified, features a voice that sounds like that of Turkey's spy chief Hakan Fidan saying: "If needed, we will launch an attack there."
The voice also talks about dispatching "four men" and launching missiles, adding: "It is not a problem. A justification can be fabricated."
The discussion also focuses on a historic site inside war-torn Syria that is technically part of Turkish national territory under an historic treaty.
The Islamic State of Iraq and the Levant (ISIL) militant group has threatened to attack the site -- a tomb of Suleyman Shah, grandfather of Ottoman Empire founder Osman -- which is located in Aleppo province.
Another voice, purportedly of Foreign Ministry Undersecretary Feridun Sinirlioglu, is heard saying that "from the point of legitimacy, the whole world would stand by us in case of an operation against ISIL".
Erdogan's parliamentary opponents have in the past accused him of planning military action in Syria to distract voters from his domestic troubles.
Main opposition leader Kemal Kilicdaroglu this month warned that Erdogan "could decide to move the army into Syria before the elections" and cautioned the military against it, saying: "Don't send Turkey on an adventure."
Davutoglu told AFP on Wednesday that "Turkey is ready to take any legitimate step under international law if its national security, including the area where the tomb of Suleyman Shah is situated, is threatened".
In the recording, a voice allegedly belonging to Davutoglu is heard saying: "Between you and me, the prime minister said over the telephone that this (attack) should be used as an opportunity when needed."