Gyurcsany secured the votes of 207 of the 386 members of parliament on, a month after a tape in which he admitted lying to voters was leaked to the media.
But just minutes after the vote, about 80,000 opposition supporters gathered outside parliament to call for his resignation.
Gyurcsany earlier told parliament he would not bow to opposition "blackmail" and vowed to stick to his tough economic programme.
In a speech before the confidence vote, he said: "I call on parliament not to give in to threats and street blackmail organised by the opposition."
He has faced calls to quit after a tape in which he said "we lied in the morning, we lied in the evening" was leaked to the press.
Gyurcsany apologised for the tone of his leaked comments, and for not being brave enough to tell the truth in the election campaign, but did not apologise for lying to the voters.
He also stood by his plans for widespread economic reforms which have helped fuel opposition anger.
He told parliament on Friday: "We must stick to this programme... balance is needed, reforms are needed and development is needed for this country."
Gyurcsany called the vote to win parliament's backing for his plans to slash the budget deficit, the biggest in the European Union. He has a 34-seat majority in the assembly.
The main opposition Fidesz party said the prime minister had not allowed people to vote in April based on facts about the economy.
Tibor Navracsics, Fidesz parliament group leader, said: "You lied in the election campaign, you based your election campaign on lies."