Updated

President Obama pledged a "lasting commitment" to the governments of Pakistan and Afghanistan on Wednesday, after holding a landmark meeting with the presidents of both countries.

Obama said the meeting with Afghan President Hamid Karzai and Pakistani President Asif Ali Zardari was "extraordinarily productive."

Amid lingering tensions among all three nations, Obama stressed that the U.S. interest in the neighboring countries lies not only in joining them in the fight against Al Qaeda and the Taliban but in supporting their respective prosperity and security.

He said he hopes the countries someday will be linked by a "shared peace" rather than a "common enemy."

"The road ahead will be difficult. There will be more violence and there will be setbacks," Obama said. "But let me be clear. The United States has made a lasting commitment to defeat Al Qaeda but also to support the democratically elected, sovereign governments of both Pakistan and Afghanistan. That commitment will not waver, and that support will be sustained."

Obama spoke after holding a face-to-face meeting with both leaders at once. He also met separately with them.

"I'm pleased that these two men, elected leaders of Afghanistan and Pakistan, fully appreciate the seriousness of the threats that we face and have reaffirmed their commitment to confronting it," Obama said at the White House. The presidents of the two countries stood at his side.

The high-stakes diplomacy had Karzai and Zardari meeting with U.S. officials separately and together, first at the State Department and then at the White House. Looming over the sessions was a U.S. bombing on Monday in Afghanistan that officials there said killed dozens of civilians and for which the Obama administration apologized.

Secretary of State Hillary Clinton told Karzai earlier that the Obama administration "deeply, deeply" regretted the loss of civilian lives. When Obama went before the cameras, he pledged his administration would "make every effort to avoid civilian casualties" in both Afghanistan and Pakistan, where U.S. airstrikes have stoked anti-American sentiment.

It's unclear what exactly happened in the bombing. Gen. David McKiernan, top U.S. commander in Afghanistan, said U.S. forces joined the operation after Taliban members beheaded three civilians. He said he had information that leads to "distinctly different conclusions" about the causes of the casualties than those reports blaming the U.S.

Senior defense officials told FOX News an initial investigation indicates that there might have been a "concerted effort by the Taliban to make it look like the U.S. was responsible for civilian casualties," though the U.S. may not have been.

The bombing issue arose earlier Wednesday, when Karzai ordered a probe into allegations by local officials that more than 30 civilians were killed by U.S.-led troops battling militants in western Afghanistan. The International Committee of the Red Cross said a team it had sent to the area saw "dozens of bodies in each of the two locations," including women and children.

Clinton earlier called the meeting she held with the presidents of both countries a "breakthrough" and said she was "very optimistic" about them.

"It was a physical manifestation of our strategy, viewing Afghanistan and Pakistan as a regional challenge but also a regional opportunity," she said.

Clinton also said that Pakistan's military offensive this week against the Taliban in the northwestern Swat Valley was a positive sign. "I'm actually quite impressed by the actions the Pakistani government is now taking," she said. "I think that action was called for, and action has been forthcoming."

Pakistan launched an offensive against the Taliban in the region after the collapse of a peace deal that had seen the extremists expand their territory toward the capital, compromising the government's hold on power.

The Associated Press contributed to this report.