The Afghan parliament on Saturday dealt President Hamid Karzai a painful political blow when they rejected 17 out of 24 of his cabinet nominees, including several close allies and former guerrilla commander Ismail Khan.

The justice, commerce, energy, economy, public health and communications portfolios are among those still open after parliamentarians made full use of a rare opportunity for a public slap in the face for Karzai.

Karzai was unsuccessful before the presidential election and he is unsuccessful after the election. His choice and his decision is not correct for parliament and it is not correct for the country, said Ahmad Shah Ahmadzai, a former prime minister.

The president should now resign, he must resign.

Cabinet approvals are one of the few areas where parliament has genuine power to hold the government's executive to account.

At a time when security and corruption problems are worsening dramatically, representatives appear to have been relishing that influence, quizzing ministers for over a week on past policy and future plans.

The secret ballot system raised speculation about ministers buying votes but also may have encouraged votes against powerful figures such as Khan.

Parliament stayed open for about six extra hours to finish the laborious processing of votes. Many ministers had considered the confirmation proceedings little more than a formality, but they turned into tense political drama.

Yes and No ballots for each minister were counted out in front of parliament and the session ran late into the evening. One nominee was rejected by a margin of just two votes.

TRUSTED HANDS OR NEW IDEAS?

Karzai's nominations kept many key ministers in posts they have held since before the presidential election in the autumn. Many of his Western backers were satisfied to see technocrats stay in position, but critics said the president was recycling old names at a time when the country needs new ideas.

The highest-profile scalp claimed by parliament was Khan, a renowned anti-Soviet guerrilla leader and anti-Taliban commander who was also energy minister in the last cabinet.

He is unpopular with some because of his role in an era when Afghanistan was split by civil war.

Khan received two more votes in his favor than against, but blank and spoiled votes tipped the balance against him in a system that requires candidates to get over half of votes cast, said the speaker of the house, Mohammad Younus Qanuni.

Close Karzai allies also rejected included public health nominee Sayed Mohammad Amin Fatimi and communications candidate Amirzai Sangeen. The only female candidate, women's affair's nominee Husn Bano Ghazanfar was also rejected.

Some Western diplomats said the retention of top ministers reflected the difficulty Karzai faces in recruiting people who are qualified to take on big portfolios.

(Writing by Emma Graham-Harrison; Editing by Louise Ireland)