The two leaders held wide-ranging talks at the White House on Wednesday, pledging to strengthen the often-strained ties between the nations.
The leaders also discussed tension between Pakistan and India over the disputed Kashmir region.
Mr Obama said the US and Pakistan remained important strategic partners.
The talks in the Oval Office came just hours after India accused Pakistani troops of firing guns and mortars at several dozen Indian border posts in Kashmir.
One Indian guard was killed and six others injured, according to media reports.
Mr Obama did not address the incident in remarks after their meeting, but praised Mr Sharif for “taking a very wise path in exploring how decades of tension between India and Pakistan can be reduced”.
“Billions of dollars have been spent on an arms race in response to these tensions, and those resources could be much more profitably invested in education, social welfare programmes on both sides of the border,” he said. “[That] would be good for the entire subcontinent – and good for the world.”
Mr Sharif spoke of his commitment to building a “co-operative relationship with India, and our efforts to peacefully resolve all our outstanding issues, including Kashmir”.
Relations between Islamabad and Washington nosedived more than two years ago, when US special forces killed al-Qaeda leader Osama Bin Laden in a raid on his hideout in Abbottabad in north-eastern Pakistan without giving the Pakistani government advance warning.
Their ties were further tested by the killing of 24 Pakistani troops in a US air strike along the Afghan border later in 2011.
Following the meeting, Mr Obama acknowledged that tensions and misunderstandings would persist between the two nations.
“It’s a challenge. It’s not easy,” he said.
“We are committed to working together and making sure that rather than this being a source of tension between our two countries, it can be a source of strength.”
And he pledged co-operation in “ways that respect Pakistan’s sovereignty, that respect the concerns of both countries”.
Mr Sharif said the US and Pakistan “have travelled together as friends and allies in defence of freedom and the pursuit of international peace and security”.
“Our two countries are bound by a common commitment to the cherished values of democracy,” he said.
Mr Sharif said the two had agreed to strengthen co-operation on counterterrorism.
“I also brought up the issue of drones in our meeting, emphasising the need for an end to such strikes,” he said.
He stated his top domestic priorities were the economy, energy, education and combating extremist activity.
“We both agreed that progress in these core areas is indispensable for creating new opportunities and building a hopeful future for our next generation,” Mr Sharif said.
Mr Obama said both leaders had agreed on the importance of leaving Pakistan’s neighbour Afghanistan “stable and secure” as US and coalition forces prepare to withdraw next year.
The White House said a peaceful Pakistan-Afghanistan border was critical to a successful counterterrorism and counterinsurgency effort.
Both leaders “expressed satisfaction with the positive momentum achieved in defence relations”, the White House later said in a statement.
They also pledged to abide by the commitments of the 2012 Nuclear Security Summit in Seoul, Korea, emphasising that nuclear terrorism was “one of the most challenging threats to international security,” the White House said.
Photo: Pakistan Prime Minister Nawaz Sharif (L) meets with U.S. President Barack Obama in the Oval Office of the White House October 23, 2013 in Washington, DC. (Photo by Dennis Brack-Pool/Getty Images)