Prodi won by 165 votes to 155, with his margin of victory boosted by a ''yes'' vote from all seven of Italy's unelected senators for life and one independent senator.
''It couldn't have gone better,'' Prodi said, moments after winning the vote that, had he lost, would have seen him stripped of power and probably facing the end of his political career.
The Senate vote was an uncomfortable test for Prodi as the tiny majority he won at April's national election meant he needed all his senators to be present and voting for him.
He now faces a second confidence vote, early next week, from the lower house. That will be less of a cliffhanger as he has a larger majority there due to an electoral system which awards the winning coalition extra seats.
In the Senate. the centre-left administration has 158 seats against 156 for the opposition led by Silvio Berlusconi, the former prime minister who still contests the election results and has predicted the new government will soon collapse.
''We have a solid and cohesive majority in both chambers,'' Prodi said in a speech ahead of the vote, to howls of derision from centre-right senators.
''Silvio Berlusconi will be back soon, your government will be brief,'' Renato Schifani, the head of Berlusconi's Forza Italia party in the Senate, told Prodi during the debate.
CRACKS Although Prodi survived this first test, the tension revealed cracks in his coalition whose parties range from the centre to the hard left.
A junior government party, Italy of Values, threatened to vote against Prodi in protest at his decision not to appoint a cabinet minister in charge of the interests of Italians abroad. It withdrew the threat at the last moment.
Prodi would probably have survived such a desertion, but even the talk of it just two days after becoming prime minister was a bad omen for future votes where he will have to rely on coalition loyalty to get legislation past a hostile opposition.
In his Senate speech, Prodi reiterated Italy would withdraw its more than 2,000 troops from Iraq before the end of the year, but stressed he would still pursue a close relationship with the United States in fighting terrorism.
Berlusconi prided himself on his close relationship with President George W Bush, whereas Prodi is keen to see Italy work closer with the European Union on foreign policy. But the new prime minister said he had good relations with Washington.
''As president of the (European) Commission, I constructed, together with the United States, a network of new, strong, serious, transparent relations for the fight against terrorism.'' An Italian general in Iraq, Natalino Madeddu, was quoted in today's Corriere della Sera daily as saying it was ''reasonable'' to consider a pullout in 60-80 days.
Prodi will face tougher tasks at home, where the economy has stagnated in two of the last three years and the budget deficit remains stubbornly above the EU limit of 3 per cent of gross domestic product.
REUTERS DKS BD2123