U.S. President Barack Obama made an unannounced visit to Baghdad on Tuesday, marking a new chapter in his strategy to wind down the unpopular war in Iraq and shift the United States' military focus to Afghanistan. His visit lasted just over four hours.

Obama, speaking to reporters upon arrival, said he came to Iraq for face-to-face meetings and to get a better sense of the security situation.

"We spent a lot of time trying to get Afghanistan right [but] there's still a lot of work to be done here," he said.

Obama said one major reason for his visit was to thank the U.S. troops stationed there. "They are doing extraordinary work. General [Ray] Odierno has been helping to lead a very effective operation here."

Flying secretly from Istanbul at the end of his first major international tour, Obama was to visit the scene of a war that he inherited from his predecessor, George W. Bush. It was Obama's first visit to Iraq since before his November 2008 election victory, which was bolstered by his campaign pledge to start bringing U.S. troops home.

The White House said that Obama would meet U.S. commanders and troops, and speak to Iraqi leaders by telephone.

He would call the Iraqi leaders rather than see them in person because poor visibility prevented helicopter travel, White House spokesman Robert Gibbs said.

Asked why Obama had come to Iraq, Gibbs said "there are several important reasons, not the least of which is to see and spend some time with the men and women who are serving our country honorably here."

Obama flew into the country hours after a car bomb exploded in a Shiite neighborhood of the capital city. His visit came at the conclusion of a long overseas trip that included economic and NATO summits in Europe and two days in Turkey.

Haaretz exclusive: Obama to visit Israel, West Bank in June

Obama is planning to visit Israel and the West Bank in June, according to an announcement circulated among American diplomatic representations in the region.

A senior diplomatic source confirmed to Haaretz that a decision was made in recent days to include a short visit to Israel and the Palestinian Authority during a visit in June to France, where President Nicolas Sarkozy will host Obama.

While in Turkey on Tuesday, Obama said that he believed peace in the Middle East was possible but said Israelis and Palestinians must make compromises.

"I think we have a sense of what those compromises should be and will be. Now what we need is political will and courage on the part of leadership," Obama told a students meeting in Istanbul at the end of a two-day visit to Turkey.

The decision to visit Jerusalem several weeks after his first meeting with Prime Minister Benjamin Netanyahu in Washington is meant to emphasize Obama's commitment to an active role in achieving a two-state solution for the Palestinian-Israeli conflict.

Before Obama's visit to Israel, the special envoy to the Middle East, former senator George Mitchell, will make another visit to the region.

An American official told Haaretz over the weekend that contrary to the Bush administration, Obama does not oppose the inclusion of Hamas in a Palestinian unity government.

However, the United States insists on the criteria set by the international Quartet - the U.S., EU, UN and Russia - as preconditions for any diplomatic exchanges with Hamas. It insists that the militant Islamic group cease violence, recognize Israel and accept previously signed accords between Israel and the Palestine Liberation Organization.

The Americans also ask that Palestinian Prime Minister Salam Fayyad, who has resigned, return to head the next Palestinian government and be responsible for the PA's finances.

A Palestinian source told Haaretz Monday that in the coming days PA President Mahmoud Abbas is likely to ask Fayyad to form a new government, without the participation of Hamas. The two main Palestinian factions, Fatah and Hamas, have failed in recent weeks to agree on a reconciliation package, mediated by Egypt. They have also failed to form a unity government comprising mostly technocrats.

In Israel, Obama will also discuss Iran's nuclear program with Netanyahu and Defense Minister Ehud Barak.

Last July, during a visit to the region as a presidential candidate, Obama said a nuclear Iran would alter the "rules of the game," not only in the Middle East, but in the entire world. He promised that if elected he would work to prevent a nuclear Iran.

But in a speech in Turkey Monday, Obama emphasized the need to prevent a nuclear-armed Iran, not a nuclear Iran.

The change in tone was interpreted in Jerusalem as an American willingness to compromise with Tehran so Iran would be able to acquire nuclear technology for civilian purposes.

The two-state solution and the nuclear question were dominant in Obama's speech Monday, as he began his first visit to a Muslim country since being elected. Speaking before the Turkish parliament, Obama said he will "actively pursue" a two-state solution in the Middle East and reiterated the U.S. commitment to the Annapolis process.

"Let me be clear: The United States strongly supports the goal of two states, Israel and Palestine, living side by side in peace and security," he said. A two-state solution "is a goal that the parties agreed to in the road map and at Annapolis," and that is "a goal that I will actively pursue as president."

Obama's mention of Annapolis comes less than a week after Israel's new foreign minister, Avigdor Lieberman, said Israel was not bound by the Annapolis process, which calls for discussions on final-status issues. Lieberman, however, expressed a commitment to the 2003 road map for peace.

Obama also said Turkey could "help the Palestinians and Israelis make this journey" and praised the Turks for supporting recent talks between Syria and Israel.

"We must not give in to pessimism and mistrust," he said. "We must extend a hand to those Palestinians who are in need, while helping them strengthen institutions. And we must reject the use of terror, and recognize that Israel's security concerns are legitimate."

Obama also said that peace in the region "will also be advanced" if Iran "forgoes any nuclear weapons ambitions," reiterating his interest in engagement with the Islamic republic and giving Iran's leaders a choice between building a weapon or a "better future for their people."

In response, a spokesman from the Prime Minister's Bureau said the Netanyahu administration pledges to work with the United States for Mideast peace.

"The government of Israel is committed to both of these goals and will formulate its policies in the near future so as to work closely with the United States," the bureau said in a statement, without mentioning Annapolis or Palestinian statehood.