US President Barack Obama has landed in Afghanistan on a surprise visit to US troops in America's longest war.

He landed at Bagram air base outside Kabul in the late evening.

His visit comes as Afghanistan expressed anger at the US for allegedly monitoring almost all the country's telephone conversations after revelations by the Wikileaks website.

Wikileaks editor Julian Assange said on Friday that Afghanistan was one of at least two countries where the US National Security Agency "has been recording and storing nearly all the domestic (and international) phone calls".

The Afghan government responded to the claims by ordering the interior and telecommunication ministries to stop illegal monitoring of calls, and said it would lodge a complaint with the US.

"These activities are an obvious violation of agreements based on technical use of these (telephone) stations," said a government statement.

"Most importantly, it is a violation of the national sovereignty of Afghanistan, and a violation of the human rights guaranteed to all Afghans."

Relations between Afghanistan and the US have been severely strained in recent years over issues of Afghan sovereignty, including detention of Taliban militant suspects in US-run jails.

President Hamid Karzai has also launched bitter attacks on the US for civilian casualties in air strikes, night raids on private houses and alleged abuses by special force commandos.

Much of the criticism has infuriated Washington as Mr Karzai has relied on US military and civilian support since he came into power after the Islamist Taliban regime was ousted in 2001 with US assistance.

Mr Karzai is due to step down after a second-round election next month to choose his successor.

In his last year in office he refused to sign an agreed text that would allow about 10,000 US soldiers to stay in Afghanistan after 2014 to help with military training and counter-terrorism.

Revelations that the US monitored all telephone calls in at least one country emerged in March, but no country was immediately named due to security concerns.