Virginia Raggi has been elected as Rome's first female mayor in a triumph for the populist Five Star Movement (M5S), representing a blow to Matteo Renzi, Italy's prime minister.

Raggi swept into City Hall on Sunday with two-thirds of the votes cast in a runoff contest with Roberto Giachetti of Renzi's centre-left Democratic Party (DP).

"A new era is beginning with us," said Raggi after declaring victory. "We'll work to bring back legality and transparency to the city's institutions."

A lawyer and local councillor, Raggi has leapt from anonymity to become one of the best-known faces in Italian politics in the space of only a few months on the campaign trail.

M5S has emerged as the main opposition to Renzi's coalition and success in Rome could provide a platform for a tilt at national power in general elections due in 2018.

WATCH: Italian right-wing activists rally in Rome

More than nine million voters were eligible to take part in the second-round election in 126 communes, including Rome, Milan, Naples, Turin and Bologna.

The result is a blow for Renzi's bloc and makes her the rising star of the M5S, the anti-establishment party founded by comedian-turned politician Beppe Grillo.

Shock defeat

Besides Rome, the PD also suffered a shock defeat in Turin, losing to M5S, but held on to power in Italy's financial capital Milan.

The coalition's defeat in Rome had been expected after widespread criticism of its management of the city over the past three years, with its mayor forced to resign in 2015 in a scandal over his expenses.

However, the loss in Turin, a centre-left stronghold, was a major shock.

The incumbent, Piero Fassino, a veteran party heavyweight, was swept aside by Chiara Appendino, 31, who overturned an 11-point gap on him.

As a consolation for Renzi, the PD stayed in power in Milan, and in the northern city of Bologna, beating more traditional, centre-right candidates.

The prime minister took office in 2014 promising to revitalise Italy, but he has struggled to boost economic growth and create jobs after years of stagnation. He has also been hurt by repeated scandals in the banking sector.

Renzi has said he would not step down whatever the results on Sunday.

Instead, he has pinned his political future on an October referendum that, he says, will bring stability to Italy and end its tradition of revolving-door governments.