More than 165,000 Afghans have fled Pakistan since Islamabad issued an ultimatum to 1.7 million people a month ago to leave or face arrest and deportation, officials said Thursday.

Just over 129,000 have fled from Khyber Pakhtunkhwa province, the provincial home department said, while a total of 38,100 have crossed through Chaman in Balochistan, border officials there told AFP.

The majority rushed to the border in the past several days as the November 1 deadline approached and police began to open up dozens of holding centres to detain arrested Afghans.

Officials at the country's busiest border point at Torkham in Khyber Pakhtunkhwa province worked into the early hours of Thursday morning to clear a queue of 28,000 people that stretched for seven kilometres.

"Illegal Afghans arrived at Torkham in heavy numbers because of the deadline... People can still return voluntarily but today only 1,000 are present at the border," Abdul Nasir Khan, deputy commissioner of the border district, told AFP.