Candidates of Italy's prime minister elect Romano Prodi have been chosen as speakers of both houses of parliament, after several tense rounds of voting.
Marini's narrow election signals political difficulties for Prodi
Fausto Bertinotti becomes speaker of the lower house, while Franco Marini won the vote in the Senate.
Mr Marini was elected after three previous inconclusive rounds.
Correspondents say the protracted battle to get Mr Marini elected shows the problems the centre-left has in controlling the upper house.
Mr Prodi has a majority of only two seats in a chamber of more than 300 senators.
The BBC's David Willey in Rome says Mr Prodi will be particularly vulnerable in the upper house and the defection or sickness of only a single senator could put his future coalition at risk.
Sixty-six-year-old Mr Bertinotti, a veteran leader of a communist party in Mr Prodi's centre-left coalition, won by a simple majority in the Chamber of Deputies.
The margin was much slimmer in the Senate, where Mr Marini defeated outgoing Prime Minister Silvio Berlusconi's nominee, 87-year-old Giulio Andreotti, by just nine votes.
Applause broke out in both houses when the results were announced, signalling the centre-left's relief.
Mr Prodi said he was "very, very happy", at the outcome, Italian news agency Ansa reported.
"We have settled in," Mr Prodi was quoted as saying.
But our correspondent says there is a poisonous atmosphere developing between left and right in Italian politics.
He says Mr Berlusconi, who is still in charge of the current centre-right government and refusing to admit defeat in the recent election, is watching Mr Prodi's discomfort with ill-concealed glee.
He has argued all along that Mr Prodi cannot hope to create a stable new coalition on the basis of his very narrow election victory, our correspondent adds.
Ballot paper confusion
Mr Bertinotti failed to win a two-thirds majority during Friday's voting, which descended into chaos as the secret ballots failed to elect either speaker.
In the race for the Senate, Mr Marini seemed to have the most support but fell short of the 162 votes needed for victory.
A second round then appeared to give Mr Marini the required majority. However, centre-right politicians said his first name was mis-spelt as "Francesco" on three ballots - and thus the vote was invalid.
There was more confusion about names on ballot papers in the third round.
The main business of the new parliament initially will be to elect a new head of state to replace President Carlo Ciampi whose mandate expires next month - only then can a new government be sworn in.