Suspect in attack, which took place as Enrico Letta's new government was being sworn in a mile away, named as Luigi Preiti

The ministers in Italy's new left-right coalition cabinet were sworn in on Sunday as gunfire broke out in the centre of Rome.

About half a mile away from where the ceremony was taking place, a lone gunman opened fire on Carabinieri officers standing guard outside the prime minister's office. One of the policemen was wounded in the neck, and another in the leg. A pregnant female passerby was grazed by a bullet and was also taken to hospital. None of the injuries were life-threatening.

The violence added a new layer of tension to the atmosphere in a divided country that had been politically deadlocked since a general election in February.

The rightwing mayor of Rome, Gianni Alemanno, said: "We shouldn't be surprised at a time when people are inveighing continually against the establishment."

Though he denied that it was aimed at any one group, Alemanno's remark was widely seen as a reference to the maverick Five Star Movement (M5S), which has bitterly attacked Italy's mainstream parties. Beppe Grillo, the ex-comedian who leads the M5S, condemned the shooting.

Rome prosecutor, Pierfilippo Laviani, told reporters he had questioned the alleged assailant, who was taken to a hospital with bruises after being wrestled to the ground. He identified the man as Luigi Preiti, 49, from Calabria, a southern agricultural area plagued by organized crime and chronic unemployment. Laviani said Preiti had "confessed everything" and didn't appear mentally unbalanced.

"He is a man full of problems, who lost his job, who lost everything," the prosecutor said. "He was desperate. In general, he wanted to shoot at politicians, but given that he couldn't reach any, he shot at the Carabinieri" paramilitary police.

The man's brother, Arcangelo Preiti, said: "Until yesterday morning, Luigi was a lucid and go-ahead person." He said his brother, who has a son, had returned to Calabria from the north after losing his job and separating from his wife.

Preiti was said not to have any links with organised crime. Forensic officers reportedly found seven bullet casings in the broad, paved square in front of the prime minister's official residence.

Not far away prime minister Enrico Letta's ministers stepped forward one by one to swear allegiance to the republic before President Giorgio Napolitano. Letta's new cabinet has the highest proportion of women - seven out of 22 - in the history of the Italian republic. The most senior is the foreign minister, Emma Bonino, a member of the Radical party and a former European commissioner. The cabinet includes nine members from the Democratic party (PD), including Letta; five from Silvio Berlusconi's Freedom People movement, and three from Civic Choice, the party launched by the previous prime minister, Mario Monti.

Letta was asked by President Napolitano to pull together a "grand coalition" after the resignation of the PD's leader, Pier Luigi Bersani. The PD won the most seats in parliament at the general election in February, but Bersani refused to do a deal with Berlusconi yet failed to entice Grillo's M5S into a coalition.

The new prime minister is to set out his government's programme to parliament today, before submitting it to confidence votes in both houses. Though created with the help of the two biggest mainstream parties, most commentators were predicting that its life could be turbulent and relatively short.

There are numerous issues on which the PD and the PdL have diametrically opposed views, starting with Berlusconi's campaign pledge to abolish an unpopular property tax and return to the electorate the €8bn it brought in last year. Renato Brunetta, the PdL leader in the lower house, warned his party would not back the government in the confidence votes if Letta failed to include the undertaking in its programme.

Though Berlusconi will not have a seat in cabinet, he will be the decisive influence behind the scenes. Angelino Alfano, whom he once named as his successor, will be the interior minister and Letta's deputy. The M5S, which took a quarter of the votes in February, will be the biggest party in opposition. Also opposing the government will be the Northern League and - at the other end of the political spectrum - the Left, Ecology and Freedom (SEL) party.