Imran Khan has outlined plans to grant citizenship to an estimated 1.5 million Afghan refugees, many of whom have lived in Pakistan for decades.

The Pakistani prime minister made the surprise announcement during his first visit to Karachi since his election last month.

He indicated that passports would be given not only to children who were born and brought up in the country, but also to their parents.

However, following a backlash, he later appeared to row back on the plans, saying he had raised the issue of refugee citizenship "just to initiate a debate" and that no decision had been made.

Speaking at a fundraiser for dam construction on Sunday, Mr Khan said the lack of documentation and education had prevented the refugees from getting jobs or accessing the social security system, rendering them an "underclass".

“If you are born in America you get an American passport," he said. "It happens in all countries around the world so why not here?

“Those Afghans whose children are born here and have grown up in Pakistan we will also, God willing, get [passports] for them.

“Why are they treated without dignity? They are humans, how have we deprived them for 30, 40 years?”

Mr Khan also promised citizenship for the more than 250,000 Bengalis in Pakistan.

The announcement was criticised by the opposition Pakistan People’s Party, with provincial minister Saeed Ghani claiming that Pakistan could not afford it.

The party's leader Saeed Ghani said he was "strongly opposed" to granting citizenship to people he described as "illegal immigrants".

"They should be registered and given work permits as well but giving them citizenship will create problems," he added.

Addressing Pakistani parliament on Tuesday, Mr Khan reiterated his ambition to grant citizenship for refugees but promised a consultation on the issue.

He said he would seek opinions from opposition politicians' before any decision was made.

Pakistan has the largest refugee population in the world, according to the UN. Afghans began pouring into the country when their homeland was invaded in 1979 and by the end of 2001, following the US invasion, there were an estimated four million refugees living there.

Imran Khan sworn in as Pakistan's prime minister

Although many have since returned, the UN High Commission for Refugees (UNHCR) says there are more than 1.4 million registered Afghan refugees in Pakistan, with around 1 million of those being second or third generation.

Other estimates put the total number of Afghans as high as 2.5 million, including between 600,000 and one million unregistered refugees.

Around 60 per cent were born in Pakistan, suggesting around 1.5 million refugees would benefit from the citizenship proposal.

The prime minister’s announcement relieved concerns that Pakistan planned to deport refugees back to Afghanistan. Earlier this year the government extended Afghans' permission to stay for just 60 days instead of the recommended five months.

Relations between the two countries had been deteriorating after the Taliban mounted a series of attacks across the border.

Human rights activists welcomed the announcement. “Pakistan has been host to one of the largest refugee populations in the world and granting citizenship to those eligible seems to be a logical next step both legally and morally,” said Saroop Ijaz, a representative for Human Rights Watch.

“This move is an important first step in ending the discrimination faced by refugee and migrant communities.”

Mr Khan also said undocumented immigrants from Bangladesh would be given passports. It was estimated that there were two million living in Pakistan in 2012.