Democratic presidential candidate Barack Obama has promised to pull United States troops out of Iraq and send more troops into Afghanistan against the Taliban and al-Qaeda if he is elected.
In a foreign policy speech at the International Trade Center in Washington on Tuesday, he said the conflict in Iraq must be brought to an end.
Mr Obama said the focus on Iraq is not a sound strategy for keeping the US safe.
He said the top priority would be to finish the fight against the Taliban and al-Qaeda in Afghanistan and Pakistan.
His Republican rival accused Mr Obama of contradicting himself over Iraq.
Senator John McCain said an increase in US troops in Iraq was working, and the the same strategy should be applied to Afghanistan.
Mr Obama is due to set off soon for a tour of Iraq, Afghanistan, Israel, the West Bank and Europe.
He has proposed adding two US combat brigades, about 9000 troops, to the 36,000 troops already in Afghanistan, saying this would be made possible by a drawdown of troops from Iraq.