In an interview ahead of this week's state visit to London, Mr Obama described the killing by US Navy Seals of al-Qaeda mastermind Osama bin Laden in his compound in Abbottabad earlier this month as a "powerful moment" for America.
The president insisted he wanted to establish a more "co-operative relationship" with the government in Islamabad after the outrage in Pakistan over the US action, which was carried out without notifying the authorities there.
But asked what he would do if the Americans found another "very high value target" in the country - such as a top al-Qaeda figure or the Taleban leader Mullah Omar - he indicated he would act again.
"I've always been clear to the Pakistanis - and I'm not the first administration to say this - that our job is to secure the United States," he said.
"We are very respectful of the sovereignty of Pakistan. But we cannot allow someone who is planning to kill our people or our allies' people - we can't allow those kind of active plans to come to fruition without us taking some action.
"Our hope is, and our expectation is, that we can achieve that in a way that is fully respectful of Pakistan's sovereignty.
"But I had made no secret - I had said this when I was running for the presidency - that if I had a clear shot at bin Laden that we'd take it."
Mr Obama acknowledged that the raid on bin Laden's compound had been a "calculated risk" which could have ended very differently.
"There's no doubt that that was as long a 40 minutes as I care to experience during my presidency," he said.
On Afghanistan, the president said that while international forces had succeeded in knocking the Taleban "back on its heels", in the end there would have to be a political settlement.
"Ultimately, it means talking to the Taleban, although we've been very clear about the requirements for any kind of serious reconciliation," he said.
"The Taleban would have to cut all ties to al-Qaeda, renounce violence, and they would have to respect the Afghan constitution. Now those are some fairly bare- bones requirements."
Mr Obama also spoke warmly of the relationship he and his wife, Michelle, had established with the Queen and the Duke of Edinburgh, who they met when they attended the G8 summit in London in 2009.
"They are extraordinarily gracious people. They could not have been kinder to us," he said.
He disclosed that when Mrs Obama returned to Buckingham Palace with their two daughters, they had been given the chance to ride through the grounds in one of the carriages.
"She [the Queen] could not have been more charming and gracious to the girls," he said.