BAGHDAD, Iraq (CNN) -- Sen. Barack Obama said he found "a strong, emerging consensus" for the redeployment of U.S. combat forces from Iraq, with Prime Minister Nuri al-Maliki telling Obama he hoped American combat troops will be gone in two years.
Sen. Barack Obama rides in a helicopter Monday with Gen. David Petraeus in Baghdad, Iraq.
Violence in Iraq has declined significantly, but "political progress, reconciliation and economic development continue to lag," Obama said in a statement with two senators who toured Iraq with him -- Sen. Jack Reed, a Democrat, and Sen. Chuck Hagel, a Republican.
"America has a strategic opportunity to build a new kind of partnership with Iraq," Obama and his colleagues said, "and to refocus our foreign policy on the many other pressing challenges around the world -- starting with the resurgence of al Qaeda and the Taliban in Afghanistan and Pakistan."
Obama, the presumptive Democratic nominee for president, has made ending the Iraq war a cornerstone of his historic run for office.
As for the future American role in Iraq, he said Iraqis want continued U.S. help training Iraqi security forces and help conducting counter-terrorism operations. He said the Iraqi leadership also requested American help in developing Iraq's economy and "advancing political compromise."
Obama, Reed and Hagel said they raised concern about Iranian backing to militias that have attacked U.S. and Iraqi troops in Iraq.
They also expressed their view that legislatures in the United States and Iraq should approve any long-term security agreements between the two countries.
In addition, Obama and his senate colleagues stressed the importance of doing more to help Iraqi refugees, who have fled the country, as well as those who are displaced within Iraq.
"We came to consult with our military leaders, embassy team and the Iraqi government about a way forward in Iraq that advances the interests of the United States, Iraq and the entire region," Obama, Reed and Hagel said. iReport.com: Tell us the most important thing the next president needs to know about Iraq
The presumptive Republican nominee for president, Sen. John McCain of Arizona, criticized Obama on Monday for opposing President Bush's "surge" of additional troops to Iraq.
"He railed against it. He voted against the surge and he said it would fail," McCain told CBS. "He was wrong there, and there's very little doubt in my mind that he will see for himself that he had a gross misjudgment and he will correct that."
McCain made similar comments in an interview on ABC, taking subtle jabs at Obama for failing to meet with the top U.S. general in Iraq, David Petraeus, until now.
"I'm glad that Senator Obama's going to get a chance for the first time to sit down with General David Petraeus and understand what the surge was all about, why it succeeded and why we are winning the war," he said. "And that is because we carried out a strategy which has succeeded, and Sen. Obama rallied against, voted against, and used his opposition to the surge as a way of gaining the nomination of his party."
Obama met Monday with U.S. and British troops in Basra, American military commanders and the Iraqi prime minister, as well as with the Iraqi president and other top officials.
Al-Maliki's office said earlier that the prime minister had underscored the notion of a "general time horizon" for any future American troop withdrawals from Iraq.
The Iraqi government has been pushing for the United States to set a general timetable to spell out troops withdrawals. The countries are negotiating a security agreement that would define the presence of U.S. troops in Iraq, and the notion of a general time frame recently was made part of the negotiations.
Iraqi Vice President Tariq al-Hashimi also met with Obama on Monday and told reporters afterward that they discussed the security agreement.
"I told Senator Obama (that) Iraqi and American negotiations regarding this are ongoing, and today new Iraqi-American negotiations on this agreement have started with Iraqi written proposals and have a timetable for the withdrawal of U.S. troops from Iraq," he said.
The Bush administration has opposed timetables for troop withdrawals. But al-Maliki and President Bush last week agreed to a "general time horizon for meeting aspirational goals" on troops cuts. The prime minister reiterated that principle with Obama, according to a statement from al-Maliki's office about their discussions.
"Developments of the situation and the circumstances is what will decide the presence of foreign troops in Iraq, but without keeping open-ended dates," al-Maliki said, according to a statement from his office.
"With the developments on the ground we can set a vision and clear horizons regarding this issue and this is a view both sides agree on in the ongoing negotiations."
Al-Maliki also stressed that approving an agreement between the countries would require the approval of the Iraqi parliament and that the declaration of principles mentions national sovereignty as a basis for negotiations.
"We hold onto that principle," al-Maliki said, according to his office.
Al-Maliki's office said Obama congratulated al-Maliki on his government's achievements and expressed pride in the relations between the countries and developments in Iraq.
Al-Maliki's office quotes Obama as saying he is "supportive and committed to preserving the gains achieved by the Iraqi government" under al-Maliki's leadership, and that he admires al-Maliki's courage.
Obama has said he would like to withdraw U.S. combat troops from Iraq within 16 months of taking office, and the prime minister appeared to back the idea of a timetable in an interview with the German magazine Der Spiegel over the weekend. See the stops on Obama's trip »
An Iraqi government spokesman said Saturday that the prime minister's comments to the magazine had been "misunderstood," and the White House said al-Maliki has made clear that any withdrawals would be conditioned on "continuing positive developments."
In a brief statement Sunday, the magazine said it "stands by its version of this interview."
Iraqi government spokesman Ali al-Dabbagh on Monday said the government's "vision" is that most U.S. combat troops would be out of Iraq by 2010. Asked whether that stance is part of the current negotiations, al-Dabbagh said, "No. This is the Iraqi vision."
An official from al-Maliki's office said the meeting with Obama was "very good and successful for both sides."
It is the Illinois senator's second trip to Iraq, after a visit in 2006. The current trip began in Kuwait and Afghanistan and will continue with scheduled stops in Jordan, Israel, the West Bank, Germany, France and England.
Obama has said that, if elected, he will commit more troops to Afghanistan and order the military to end the war in Iraq, which he has called a "dangerous distraction" from the war against terror.
Obama spent Saturday and Sunday in Afghanistan, where he met with U.S. troops at three bases and with Afghan President Hamid Karzai -- a leader the Democratic senator has criticized for doing too little to rebuild the war-torn nation. Watch Obama meet Karzai, U.S. soldiers in Afghanistan »
Republican presidential candidate John McCain criticized Obama's proposals as naive and premature. He has said Obama was wrong to talk about his plans for Iraq and Afghanistan before he "even left, before he has talked to Gen. Petraeus, before he has seen the progress in Iraq and before" his first visit to Afghanistan, which happened Saturday and Sunday.
CNN's Jomana Karadsheh, Mohammed Tawfeeq, Frederik Pleitgen and Alexander Mooney contributed to this report.