Gilani's comments come after Afghnistan's government accused Islamabad and its intelligence agency of backing Taliban-linked fighters.
The US has said Islamabad has failed to take decisive steps against fighters opposed to the government operating in Pakistan's region bordering Afghanistan.
At the same time, US Democratic presidential hopeful Barack Obama is in Afghanistan, visiting US troops and reinforcing his pledge to redirect soldiers from Iraqi to the country should he be elected president.
Talat Masood, a defence analyst based in Islamabad, told Al Jazeera that the Pakistani government considered it necessary to show itself as being anti-Taliban.
But he said that Pakistan "was divided and confused" regarding the so-called war on terror.
Gilani's firm stance against having foreign forces in Pakistan was an attempt to make it seem like "the country owned the war", Masood said.
A spokesman for the Pakistani army said on Sunday that it had killed 15 fighters and detained 60 others, in the army's first major offensive since Pakistan's new government was formed in February.
Major-General Athar Abbas said five troops have been injured during five days of fighting near the town of Hangu in the northwest of the country.
The army operation, launched on Wednesday, came after supporters of Baitullah Mehsud, leader of the Pakistani Taliban, killed 17 troops in an ambush in the area.
An army statement said five of the killed opposition fighters had attempted to storm a military fort early on Sunday.