Supporters of the Turkish PM at an election rally in March 2014: Erdogan will try to 'convince his supporters that he is the victim of an international smear campaign'. Photograph: Adem Altan/AFP/Getty Images

Turks greeted the news that YouTube has been blocked in the country with the grimly raised eyebrows Brits reserve for an unusually bad weather forecast. "So it's come to this", they say, but no one is overly shocked. Internet bans are becoming a weekly occurrence. A week ago Twitter was banned at the personal behest of the prime minister, Recep Tayyip Erdoğan, and remains so days after a court order annulled the block.

With only days left until the municipal elections, campaigning is getting more frantic, voters more nervous and political rhetoric more extreme. At the centre of all this is Erdoğan, bombastically fighting off corruption claims and trying to stem the flow of phone recordings spreading across social media which allegedly show him and his associates engaging in large-scale corruption, media manipulation and – most recently – plotting war against Syria. The last bombshell prompted the YouTube ban; it was a desperate attempt at damage limitation.

In the key cities of Istanbul and Ankara, the race between the ruling AKP and opposition candidates has tightened. Competing parties string up bunting and aggressively patrol the streets in noisy buses, throwing carnations to passers-by and giving out free tea.

Erdoğan in particular is on fire, despite the fact he will not run in these elections, performing at rallies daily across the country to lend personal clout to his party's cause. On Thursday he sounded hoarse and shrill as he poured scorn on opponents for the umpteenth time, causing much amusement among Twitter users merrily circumnavigating the ban. Hours later, YouTube was blocked, drawing immediate attention to the recording released that day of the foreign minister Ahmet Davutoğlu and the head of the National Intelligence Organization allegedly planning a Syrian provocation. The government has not denied these tapes, instead labelling their circulation as "a declaration of war against the Turkish Republic". War machinations aside, they have a serious espionage problem on their hands.

So how to combat this unseen, insidious foe? By banning YouTube, Erdoğan is aiming at least to muffle the worst of the leaks before Sunday's elections. He cannot "eradicate" them, as he vowed to do to Twitter last week, but he can limit their exposure and attempt to discredit their source in the short time before the country goes to the polls. By painting both Twitter and YouTube (and no doubt Facebook next week) as online dens of iniquity, he aims to convince his supporters that the allegations are malicious falsehoods, and that he is the victim of an international smear campaign operating on social media. Extreme tactics; but in a country rife with conspiracy theories and pre-election tension, they might well work.

Erdoğan had already burned his bridges with the international community with the Twitter ban. Those in Turkey who consider his moves authoritarian have every reason to dislike him. Certainly, YouTube is a more popular site than Twitter, and many more people in Turkey will be affected by the ban, particularly the less politicised citizens who are not as clued up on internet block avoidance tactics as the Twitter-using community. Nonetheless, Erdoğan will almost certainly convince his core supporters that YouTube is a scourge from which they must be protected. Whatever their effect, the bans are evidence of a government in trouble.

Erdoğan is not mad, as his detractors often claim, but he is panicking. He is taking extreme action because he believes it is the only way out of a situation that might spell an ignominious end to his political career. At this point, sadly, Turkey is not a place of political discourse or moderation. The upcoming elections are essentially a popularity test for one man, and he is taking every step to make sure he wins.