Matteo Renzi is not the first government leader to hit mid-term doldrums. And it can be argued that, in Rome especially, the populist, internet-based Five Star Movement (M5S) benefited from a localised protest vote against sleaze.

But the setback the M5S inflicted on Italy’s chirpy young prime minister on Sunday could scarcely have been more ill-timed for him. Like David Cameron, but even more explicitly, Renzi has staked his political future on a referendum: in the autumn, probably at the start of October, Italian voters will be called to vote on what he sees as the keystone of his two-year-old government.

Like the man who gave him his job, the former president, Giorgio Napolitano, Renzi believes the M5S represents a challenge to the very survival of Italy’s parliamentary democracy. To understand why, you have to go back to the 2013 general election.

Anti-establishment candidates elected to lead Rome and Turin Read more

The M5S – founded by the comedian Beppe Grillo – and his digital guru, Gianroberto Casaleggio, only four years earlier – scooped a quarter of the votes. And since Grillo refused to negotiate with the established parties, which he regards as irredeemably corrupt, the result was stalemate.

Had it not been for a deal between left and right, Italy would have become as deadlocked as Spain since its general election in December, and for a not dissimilar reason: the success of new political movements outside the mainstream. So the grand plan – though only voiced privately – was to nobble the M5S by introducing a new electoral law and a constitutional reform.

The latter would ensure only one of Italy’s two houses of parliament would have any real clout and, at the next general election, the party that topped the poll would get an outright majority of its seats. That party’s leader, which Renzi has always assumed would be himself, would thus enjoy a full, five-year term in office. What is more, because of the new electoral law which means lawmakers will continue to be accountable to their party leaders rather than their constituents, his new government could expect to be untroubled by party revolts.

The grand plan dovetailed with two other, sincerely-held, concerns. One is the widely-held belief that Italy’s existing arrangements, involving two chambers with equal powers and identical duties, make it impossible to legislate at anything but snail’s pace. The other, popular with Renzi’s economic advisers, is that the difficulties of its slow-growing economy will remain unresolved until it has a leader able to face down the vested interests standing in the way of modernisation.

But to ask the voters of a nation with Italy’s unhappy, authoritarian past to entrust so much power to one person is to ask a lot. To bring his grand plan to a successful conclusion, Renzi needs to count on a huge reservoir of goodwill. The electorate must be convinced above all that he wants to gather power to himself, not in his interests, but in theirs.

Until recently, he could count on just that kind of support. At the European elections in 2014, his party, the centre-left PD, defied a continent-wide trend to bring home more than 40% of the vote. Angela Merkel was so impressed that when they next met she hailed Renzi as “the matador”.

Facebook Twitter Pinterest Turin’s newly elected mayor, Chiara Appendino, delivers a speech at city hall after her victory in the mayoral election. Photograph: Marco Bertorello/AFP/Getty Images

The results from Sunday’s elections have besmirched his suit of lights at just the moment when he most needs to impress the crowd and rouse it to an impassioned olé. Even more damaging than Virginia Raggi’s victory in Rome was Chiara Appendino’s unexpected triumph in Turin, a traditional stronghold of the left. Appendino’s opponent was a formidable one: Piero Fassino, a former leader of the party that morphed into the PD.

The moderate left won power in Milan. But even before Sunday’s run-offs, the PD’s candidate had dropped out of the running in Naples where voters once again plumped for their radical left mayor, Luigi de Magistris.

Much will now depend on how the inexperienced Raggi and Appendino fare between now and October. Much will also depend on how Renzi reacts.

But time is shorter than it may appear to be. Within less than six weeks, Italians will be retreating to the beaches and by the time normal business resumes in September, the referendum will be less than a month off.

The M5S’s success may have raised questions over Renzi’s ability to win that crucial vote. But there is another, even more fascinating question starting to form a little further down the road.

The latest poll shows the M5S running a mere 0.4% behind the PD. What if Renzi were to win the referendum, install a winner-takes-all system, but then lose the general election that is expected to be called shortly afterwards?

The grand plan has always foreseen the new, more extensive powers being conferred on Matteo Renzi, not on Beppe Grillo.