The death toll from the twin suicide bombs at a peace rally in Ankara on Saturday has reached 128. The Turkish police were not present to provide security (they never are at “opposition” events), but they did show up to fire tear gas at the mourners afterward.

Who did it? Prime Minister Ahmet Davutoglu offered three possibilities: the Kurdish separatist organization PKK; anonymous “extreme leftists”; or Islamic State. Selahattin Demirtas, the co-leader of the pro-Kurdish HDP party that organized the rally, offered a fourth alternative: people trying to advance the interests of President Recep Tayyib Erdogan’s Justice and Development (AK) Party.

The atrocity certainly served Erdogan’s strategy of creating an atmosphere of fear and impending calamity before the elections on Nov. 1, in which he hopes to get back the parliamentary majority he lost in the June elections. But it’s hard to believe that the AK Party has suicide bombers at its disposal: It is an Islamic party, but nothing like that extreme.

It’s equally unlikely to have been the work of the PKK, because a very large proportion of the people at the rally were Kurds. Moreover, the PKK is a secular organization, which makes it an improbable source of suicide bombers. The suggestion that “extreme leftists” were responsible is ridiculous: What would be their motive? Which leaves Islamic State as the probable perpetrator.

Islamic State uses suicide bombers as a matter of course, and it is certainly angry at Erdogan. He treated it quite well in the early years of the Syrian civil war, keeping the Turkish border open for its volunteers to flow across by the thousands. He even closed the border to Kurds who wanted to help the defenders of Kobani, a city in the northern, Kurdish-majority part of Syria — a siege that lasted four months and ended in an Islamic State defeat.

Erdogan is a deeply religious Sunni Muslim. He wanted to see the overthrow of Syria’s President Bashar Assad, an Alawite (Shiite) ruling a mostly Sunni country, and he didn’t much care who the opposition were so long as they were Sunnis. He also didn’t want to see a Kurdish mini-state appear just across Turkey’s southern border, so he preferred an Islamic State victory over Syria’s Kurds. But his priorities changed after he lost the June election. Now his own power was at stake, and to keep it he needed a crisis. In fact, he needed a war.

Assuming that the AK Party would not only win its fourth straight election this year but gain a 60 percent majority of the seats in parliament, Erdogan moved on from 10 years as prime minister and got himself elected president last year. The presidency is a largely ceremonial office, but with a 60 percent “super-majority” he could change the constitution and make it all-powerful.

But his party didn’t get 60 percent of the seats in the June election. It didn’t get a majority at all: only 258 seats in the 550-seat parliament. The main reason was that the HDP, a party demanding that Turkey’s one-fifth Kurdish minority be treated as equal citizens in every respect, including language, managed to get into parliament.

Most of the HDP’s voters were Kurds, including many conservative and religious Kurds who had previously voted for Erdogan’s party, but its secular and liberal values also persuaded many ethnic Turks to vote for it. It only got 13 percent of the vote, but that was above the 10 percent threshold a party must exceed to win any seats in parliament at all.

The arrival of the HDP changed the parliamentary arithmetic and deprived the AK of its majority. Erdogan could have opted for a coalition, but he was stranded in the powerless presidency, unable to change the constitution, and could not even personally be part of such a coalition government. So he decided to gamble on another election.

The Kurdish votes were not coming back to the AK Party, and the only other possible source were the ultranationalists who had been alienated by his peace talks with the PKK. (The talks began and the shooting stopped four years ago, although the official cease-fire was only declared in 2013.)

Now he needed to re-start the war against the PKK, and that would be most unwelcome to his American allies. He solved the problem by saying he would attack Islamic State and other “terrorists,” which got Washington on board — but since the Turkish airstrikes began in August, they have hit 20 PKK targets for every strike against Islamic State. It’s not even clear that Turkey has finally shut its Syrian border to Islamic State volunteers.

The PKK is fighting back, of course, but Islamic State has not been appropriately grateful that Turkey is only bombing it (quite lightly) for diplomatic reasons. It is almost certainly responsible for all three mass-casualty attacks using suicide bombers in Turkey this year.

There is only one consolation in all this: Erdogan’s electoral strategy doesn’t seem to be working. A poll last month showed that 56 percent of Turks hold him directly responsible for the new war. The polls also show AK’s share of the vote falling, and that of the HDP rising. Erdogan is facing defeat, and he richly deserves it.

Gwynne Dyer is an independent journalist and military historian based in London.