Gilani made the remarks while addressing a gathering in Bili Wala near his hometown of Multan in Punjab province.
He contended that the message from the US had come after he convened a meeting of all political parties to forge consensus on dealing with the tensions in bilateral relations.
He did not say when the message was conveyed to Pakistan.
"It is due to the all parties'' conference as well as the unity of Pakistan's political leaders that the US has sent a message that they need Pakistan and that they cannot win the war (against terrorism) without Pakistan," he said.
"They have also distanced themselves from the statement of (former US military chief Admiral Mike) Mullen. This is the victory of the Pakistani nation, political parties and the government's policy of reconciliation," he said.
The successful holding of the meeting of all political parties was testimony to the fact that the people are united on the issue of Pakistan''s security and defence, he remarked.
"We will never allow anyone to harbour bad thoughts about Pakistan's security. We do not desire war and want peace in the country and beyond.
"Pakistan can play an important role in peace and we will do it," Gilani said.
Pakistan is ready to hold talks with everyone for peace and can go to any extent to achieve this objective, he said.
"All the country's political forces stand shoulder to shoulder for Pakistan's security interests," he added.