US President George W Bush has praised Pakistan's role in the war on terror, but said more needed to be done to defeat al-Qaeda.
Speaking during a 24-hour visit, Mr Bush reaffirmed a "broad and lasting strategic partnership" with Pakistan.
He also said he believed the future of Pakistan lay in democracy.
Pakistani President Pervez Musharraf said he looked forward to a new era of co-operation between his country and the US.
There was, however, no sign that the US was ready to provide the same nuclear assistance to Pakistan as Mr Bush agreed to do with India, just two days previously.
"Pakistan and India are different countries with different needs and different histories," Mr Bush said.
"As we proceed forward, our strategy will take in those well-known differences."
Under the accord with India - Pakistan's main rival - India will get access to US civil nuclear technology in return for opening up its nuclear facilities to inspection.
Mr Bush did, however, drop previous objections to a proposed pipeline supplying Iranian gas to India via Pakistan.
"Our beef with Iran is not the pipeline, our beef with Iran is in fact they want to develop a nuclear weapon and I believe a nuclear weapon in the hands of the Iranians will be very dangerous for all of us," said Mr Bush.
'We will win'
Mr Bush praised Gen Musharraf for his "bold decision" to fight terror following the 11 September 2001 attacks on the US.
He said the Pakistani president "understands the stakes, he understands the responsibility, the need to make sure the strategy is able to defeat the enemy".
Mr Bush said more work remained to be done to defeat al-Qaeda.
The best way to achieve this, he said, was to "share good intelligence, to locate them [al-Qaeda], and then be prepared to bring them to justice".
He said: "We will win this war together."
President Bush said a large part of his discussions with Gen Musharraf had been on democratic reform.
"President Musharraf understands that in the long run the way to defeat terrorism is to replace an ideology of hatred with an ideology of hope," he said.
President Bush said presidential elections planned for 2007 in Pakistan were a great opportunity but they needed to be "open and honest".
Gen Musharraf, who seized power in a bloodless coup in 1999, conceded that his military post and uniform were still an issue that needed to be addressed.
But he said he was the one responsible for bringing to Pakistan the "essence of democracy".
The Pakistani president acknowledged there had been some "slippage" in his country's fight against al-Qaeda, but he said "we will succeed".
Reaffirming his support for Washington, Gen Musharraf said it was "absolutely clear - that we have a strategic partnership on the issue of fighting terrorism".
Police and troops were highly visible on Islamabad's streets
The BBC's Jonathan Beale, who is travelling with President Bush, says as the two leaders emerged from more than two hours of talks, US Black Hawk helicopters hovered in the distance - the heavy security presence further evidence that their declared war on terror has not been won.
There was intense security in and around the capital, with a no-fly zone for commercial flights and private aircraft, and thousands of riot police and paramilitary troops on guard.
Several conservative Islamic parties and student organisations have rallied supporters across the country for anti-US marches over the past week, with many demonstrators also condemning Western countries for printing cartoons that satirised the Prophet Muhammad.
Pakistani opposition leader Imran Khan was detained ahead of a march he was due to lead on Saturday, his spokesman said.