Washington must stop U.S. missile attacks on the Pakistani side of the Afghan border or risk losing the war against al-Qaida and the Taliban, Pakistan's prime minister warned.

"No matter who the president of America will be, if he doesn't respect the sovereignty and integrity of Pakistan ... anti-America sentiments and anti-West sentiment will be there," said Yousuf Raza Gilani in an interview with The Associated Press on Tuesday in his heavily guarded residence in the capital Islamabad.

Over the last two months, the U.S. has launched at least 17 strikes on militant targets on Pakistan's lawless side of the Afghan border.

Washington says the region is believed to be home to many of al-Qaida's top leaders, including Osama bin Laden, and is also used by militants blamed for rising attacks on NATO and U.S. troops in neighboring Afghanistan.

But Gilani said the U.S. attacks by unmanned drones in the semiautonomous tribal regions were "uniting the militants with the tribes. How can you fight a war without the support of the people?" he said.

The prime minister said the U.S. should share intelligence with his country's military to allow Pakistan to go after militants themselves.

As Gilani spoke, several thousand hard-line Muslims demonstrated against the strikes in a town in the border region and in the southern city of Karachi, burning U.S. flags, witnesses said.

Democratic candidate Barack Obama and Republican rival John McCain have roughly similar positions on Pakistan, though during the campaign differences in emphasis have emerged.

Obama has said if he is elected, he could launch unilateral attacks on high-value terrorist targets in Pakistan as they become exposed and "if Pakistan cannot or will not act" against them. McCain says attacks shouldn't be discussed "out loud" but has not said he disagrees with them.

On Monday, Gilani held talks with U.S. Gen. David Petraeus, who is making his first tour of the region since taking over U.S. Central Command last week.

The Pakistan army is undertaking a major offensive in the border region against militants and is trying to persuade local tribes to join the fight — a task it says is made especially difficult by the U.S. attacks.