His visit came a day after the White House defended the drone program as it disputed claims by two human rights groups that its targeted-killing program violates international law and often has killed civilians, including a grandmother in Pakistan.
Obama didn't mention the controversial targeted-killing program, but he did say the two leaders had talked about the need to work together to curb terrorism and extremism - in ways that "respect Pakistan's sovereignty" and address both countries' concerns.
"I'm optimistic that we can continue to make important strides in moving forward," the president said, noting that terrorist attacks have affected both countries. "It's a challenge. It's not easy, but we committed to working together and making sure that rather than this being a source of tension between our two countries that it can be a source of strength."
Obama said the U.S. considered Pakistan "a very important strategic partner" and thought "that if Pakistan is secure and peaceful and prosperous, that's not only good for Pakistan, it's good for the region and it's good for the world."
The president said the two had "spent a lot of time" talking about Pakistan's economy and that the U.S. would look to boost trade opportunities with the country.
They also discussed Afghanistan, and Obama said he'd pledged to "fully brief" Sharif on the Afghan elections and "long-term strategy for stability in the region." Sharif said Pakistan was committed to a "peaceful and stable Afghanistan."
The president said he was encouraged by Sharif's recent meeting with the Indian prime minister, Manmohan Singh, on the sidelines of the United Nations General Assembly in New York last month.
"I think he is taking a very wise path and exploring how the tension between India and Pakistan could be reduced," Obama said, adding that Sharif had pointed out that billions of dollars had been spent on an arms race in response to the discord.
Obama also was expected to raise the case of Shakil Afridi, a Pakistani doctor who was sentenced last year to 33 years in prison for treason after helping the CIA hunt for Osama bin Laden in Pakistan.
The U.S. thinks Afridi's treatment has been "unjust and unwarranted" and that he should be released, White House press secretary Jay Carney said. He said before the meeting that bringing bin Laden to justice "was clearly in Pakistan's interest, and the prosecution and conviction of Dr. Afridi sends exactly the wrong message about the importance of this shared interest."
Neither leader mentioned Afridi in his remarks.
Outside the gates of the White House, supporters of Pakistani former military dictator Pervez Musharraf protested his arrest in the December 2007 assassination of former Prime Minister Benazir Bhutto.
Musharraf ruled Pakistan from 1999 to 2008 after leading an October 1999 coup d'etat against Sharif, who was then in his second term as prime minister and is now back in the office after his party won elections in May.