US President George W Bush has cited Hungary's thirst for freedom as an inspiration to Iraq.
Mr Bush spoke from a scenic vantage point overlooking Budapest
On a visit to Budapest to mark 50 years since an uprising against Soviet rule, Mr Bush said Hungary represented "the triumph of liberty over tyranny".
Iraqis, he said, would take inspiration and "draw hope" from Hungary's success.
Hungary 1956 revolt was crushed by the Soviet army. Budapest finally broke free of Moscow's influence when the Soviet bloc crumbled 17 years ago.
Hungary is now a member of Nato and the European Union.
After talks with Hungarian leaders, Mr Bush laid flowers in memory of the victims of the 1956 uprising.
23 Oct: Students hold pro-democracy rally in Budapest, drawing crowd of at least 100,000
Police shoot at crowds, who react with violence
Soviet troops deployed to quell protests
Communists make Imre Nagy PM - he negotiates truce, then says Hungary to quit Warsaw Pact
4 Nov: Soviet forces launch huge offensive, crushing uprising
At least 2,600 Hungarians, 600 Soviet troops killed in fighting, while up to 200,000 Hungarians flee abroad
June 1958: Imre Nagy execution announced
"The lesson of the Hungarian experience is clear - liberty can be delayed but it cannot be denied," Mr Bush told an audience at a ceremony on a hill overlooking Budapest from which Soviet tanks had fired into the city.
The Soviet Union had "crushed the Hungarian uprising but not the Hungarian people's thirst for freedom", he said.
Mr Bush praised the new Iraqi PM, Nouri Maliki, saying Hungarians would recognise his spirit.
But, he said, Iraq's democracy was still under threat from "determined enemies".
"Defeating these enemies will require sacrifices and continued patience, the kind of patience the good people of Hungary displayed after 1956," he said.
His speech acknowledged the high cost Hungary paid in its struggle for independence and thanked it for "leadership in freedom's cause".
He also promoted a vision of democratic regimes triumphing with US backing.
Mr Bush said Americans had learned from the experience of people who had stood up to oppression.
The president's day-long trip comes after he attended a US-EU summit in Austria.
Mr Bush joined the Hungarian president in inspecting troops
His plane touched down in Budapest on Wednesday evening, where he was met by Hungarian Foreign Minister Kinga Goncz and US ambassador George Herbert Walker.
He was greeted by Hungarian President Laszlo Solyom on Thursday morning, before the pair reviewed Hungarian troops.
Soviet tanks rolled into Budapest in 1956 after a national uprising and subsequent call from Prime Minister Imre Nagy for the country to pull out of the Soviet-led Warsaw Pact.
Thousands of people died in the ensuing crackdown by Soviet forces, while hundreds of thousands more fled the country. In 1958, Soviet authorities announced Mr Nagy had been executed.
Mr Bush's visit is four months early - the official commemoration is not until October but the US president is unable to attend then.
The symbolic value of a people rising up against a dictatorial regime is close to his heart, says the BBC's Nick Thorpe in Budapest.
But Hungarians underline that they opposed the Soviet power alone, and their appeals for help from the outside world went unheeded, our correspondent adds.
During Mr Bush's visit, Hungary - which joined the EU two years ago - is expected to raise the long-standing demand for it and other recent EU members for visa-free travel to the US.
Hungarian PM Ferenc Gyurcsany said he had discussed with Mr Bush demands to ease visa restrictions for Hungarians visiting the US.
Hungary is one of nine of the 10 new EU member states that do not enjoy the visa waivers granted to most of the bloc's 15 older member states.
"I understand this is a difficult issue," Mr Bush said, adding that the two countries "have developed a roadmap" for resolving it.