Earlier this week the death toll among US forces since the war ion Iraq began in 2003 topped the 4,000 mark.
"[We] cannot consign Iraqis to genocide that would follow reckless, irresponsible and premature withdrawal," McCain said in his speech to the World Affairs Council.
"Our great power does not mean we can do whatever we want whenever we want, nor should we assume we have all the wisdom and knowledge necessary to succeed," he said.
"America must be a model citizen if we want others to look to us as a model."
McCain is almost certain to be the Republican party's candidate in November's presidential election.
'Order and stability'
George Bush, the current US president, has endorsed McCain, who faces opposition from conservative Republicans sceptical over his positions on immigration and tax cuts.
The 71-year-old, who was held as a prisoner of war during the Vietnam war, has won his party's nominating contest but is yet to be confirmed as the Republican candidate.
In his speech on Wednesday McCain said the US should "lead by shouldering our international responsibilities and pointing the way to a better and safer future for humanity."
He also admitted US policy had played a part in the emergence of radical religious groups.
"For decades in the greater Middle East, we had a strategy of relying on autocrats to provide order and stability," McCain said.
"We relied on the Shah of Iran, the autocratic rulers of Egypt, the generals of Pakistan, the Saudi royal family, and even, for a time, on Saddam Hussein.''
He said the strategy "began to unravel" in the late 1970's with the overthrow of the shah of Iran in "the radical Islamic revolution that now rules in Tehran."
McCain also said on he would devote "personal deep engagement" to peace in the Middle East if he were elected US president.
He has just returned from a trip to Europe and the Middle East, including stops in Iraq and Israel.