The Rome mayor, Virginia Raggi, has been cleared of cronyism and abuse of power after a judge ruled that the alleged offence did not constitute a crime.

Prosecutors had called for a 10-month jail term over allegations that Raggi, from the anti-establishment Five Star Movement, lied to investigators over the appointment of Renato Marra, the brother of one of her close aides, as Rome’s tourism chief. His brother Raffaele, the former head of staff at Rome city hall, faces separate corruption allegations.

The accusations emerged not long after Raggi was elected as Rome’s first female mayor in June 2016. Had she been convicted she would have been forced to resign as mayor, in line with the Five Star Movement’s code of ethics.

She wept upon hearing the ruling, saying afterwards: “This sentence wipes out two years of mud-slinging. We’ll go forward with our heads held high for Rome, my beloved city, and for all citizens.”

Luigi Di Maio, the Five Star Movement leader and Italy’s deputy prime minister, celebrated the court ruling while using the opportunity to criticise journalists whom he accused of “attacking Italy’s most massacred mayor” for two years and generating “fake news” to bring her down. “Go Virginia! I am happy for always having defended you and believed in you,” he wrote on Facebook.

During a press conference in Rome on Friday, Di Maio would not comment on the process against Raggi but made it clear that she would have to resign if convicted.

New elections would have threatened the party’s rule of the Italian capital as Raggi has come under immense pressure after failing to deliver on her promises to clean up the city. Rome is beset by myriad issues, including severe problems with rubbish collection and public transport. In recent weeks, the increasingly popular Matteo Salvini, the leader of the far-right League and the Five Star Movement’s government coalition partner, had seized on the city’s problems to make the case for his party restoring “law and order”.