At a news conference with interim Iraqi Prime Minister Iyad Allawi, Blair described the situation in the war-torn country as a "battle between democracy and terror".
"I hope it goes ahead on an inclusive basis," he said.
"There are major problems - but holding the elections will have its own impetus towards greater security."
He acknowledged that violence would continue both before and after the 30 January elections, but said: "I think that everyone understands there will be violence that will continue even after the election. On the other hand we will have a very clear expression of democratic will," he added.
The British prime minister also told Iraqi election workers he had met "that I thought they were the heroes of the new Iraq that's being created, because here are people who are risking their lives every day in order to make sure that the people of Iraq get a chance to decide their own destiny".
"When I meet the people working alongside the United Nations, Iraqis in fear of their life every day because they are trying to bring freedom and democracy to their people ... then I know we are doing the right thing," he said.
Blair flew into the Iraqi capital at about 11am (0800 GMT) aboard a British military aircraft from Jordan. His visit was kept secret until his arrival in the Iraqi capital because of security concerns.
It was his first visit to Baghdad and his third to Iraq since Saddam Hussein was toppled in April 2003. He visited British troops stationed around the southern Iraqi city of Basra in mid-2003 and in January.
The prime minister was a key supporter of the US-led invasion of Iraq that toppled Saddam.
Blair lashed out at those who blame the violence on the US-led forces and not fighters, saying the situation was a "battle
between democracy and terror".
"The danger people feel here is coming from the terrorists and
insurgents who are trying to stop the country from becoming a democracy," he said. "We stand on the side of the democrats."
For his part, Allawi said: "We are pressing ahead to having the elections on time. Our enemies are determined to break our will ... we will not allow them to prevail."