Afghanistan's government has suspended the three police special forces commanders responsible for securing the capital during crucial presidential elections, and plans to try them in a court martial for making illegal detentions and desecrating a mosque.

The three men have also been accused of collaborating with US and British commandos to serve foreign rather than Afghan aims, although they will not be tried as spies, according to an official source with first-hand knowledge of events.

Since they were removed from their positions in late April, all special operations raids by police commandos have been suspended, raising questions about security in Kabul as insurgents arrive from safe havens in Pakistan and the country prepares for the annual "fighting season".

The commanders come from one of the most respected parts of the Afghan security forces, which overall are still grappling with serious problems from corruption to drug addiction, despite years of western training and billions of dollars in funding.

The charges they are expected to face appear to be relatively minor. They will be accused of temporarily holding a man without a warrant during a night raid on a group of suspected insurgents, and entering a mosque with dogs, the source said. They will deny both charges.

President Hamid Karzai, who has for years been an outspoken critic of both night raids and illegal detentions, personally ordered the investigation and trial, in the face of opposition from top ministers and security officials.

The allegations were made by a prosecutor who works with special forces and an intelligence official responsible for monitoring police behaviour. Both have since been promoted – one given the rank of general and the other the top prosecutor's job in Panjshir province, north of Kabul.

A government official who asked not to be named confirmed that there was an investigation under way into the conduct of some special forces officers, but denied that anyone had been detained or suspended from his position. The interior ministry declined to comment on the case.

The men facing trial, whom sources declined to name because of their position as commandos, were the officers leading two elite police squads, and a third senior official who organised their logistics.

One officer headed the 333 commando unit which tackles threats nationwide, while a second was in charge of the crisis response unit, which tackles security emergencies in Kabul and also tries to preempt insurgent assaults by disrupting networks around the capital.

The final man charged was director of operations for the special forces, who organised and signed off on all the logistics for their operations and briefed others about what they did.

All three are in their early 30s, from ordinary families rather than the elite clans who dominate many sectors of Afghan politics, and have studied at military academies overseas.

It is the latest serious crisis to hit a commando force which has been celebrated across Afghanistan for its impressive track record fighting the Taliban, and is seen as critical to the country's security, but whose leadership has been buffeted by a string of political crises.

Last year the general in charge of all police special forces units sought asylum in Denmark, exhausted by internal politics. The interior ministry insisted at the time that he was on an extended leave to deal with family issues, but they have since admitted he abandoned his post.

The head of the crisis response unit had also previously been suspended from his position after Al-Jazeera broadcast a report on Afghan special forces. Karzai was outraged by the footage of his own troops searching homes and taking detainees much as foreign troops do, and demanded the commander be fired – though not the disbanding of the unit.

The commander was restored to his post in March after concerns about how security forces tackled a deadly Taliban attack on a luxury Kabul hotel, and his unit was widely praised both for their handling of a string of assaults that followed, and helping ensure election day was peaceful in the capital.

The latest dispute has consumed hours of government time and soured Karzai's ties with sections of his cabinet and with top security officials, including interior minister Omar Daudzai, who personally signs off on every special forces raid and has strongly defended his officers.

The crisis began in mid-April, when Karzai met the two men who made the allegations. It is unclear how they bypassed the hierarchy of their own organisations, and layers of presidential security, but once they laid out their charges he called key officials to the palace for an immediate meeting.

The men repeated their accusations to a gathering that included the ministers of defence and the interior, the army chief of staff and the head of the intelligence service. Karzai said he wanted the trio arrested and court-martialled, despite Daudzai and others mounting a fierce defence.

Two days later the men were called to the interior ministry and were told they would be imprisoned pending an investigation, and the next regular meeting of the national security council was dominated by discussion of the allegations.

General Ayub Salangi, who is currently a deputy interior minister but for years commanded the Kabul police, begged Karzai to reconsider in an emotional speech. "Mr President, I've been next to these guys in fights against suicide bombers in the city, that's all they do," he reportedly said.

Karzai is close to many of the ministers pleading for the commandos. Daudzai was once his chief of staff and after the meeting the president used a family nickname when discussing Salangi's speech. "Del Agha seems to be taking things very seriously today," he told aides.

But he overruled them, and demanded an investigation. After a week in jail, the three men were released to help prosecutors with their research, which they finished last week.

The specific allegations are expected to be presented in court later this month and include the illegal detention of a man called Abdullah in the night raid in eastern Kapisa province filmed by Al-Jazeera, and the use of dogs to search a mosque in a raid nine months ago. That is a violation in Afghanistan because the animals are considered unclean.

The attorney general and Daudzai presented a preliminary report to Karzai in mid-May. It found, the source said, that all operations were in accordance with Afghan law, and the accusation they searched mosques with dogs was spurious because the units do not have any working animals.

There was no record of a man called Abdullah being detained in the Kapisa raid in the pages of documentation required for all operations. The prosecutor who made the allegations signed off on these documents at the time, and did not raise any concerns, the source said.

But Karzai rejected the findings and personally called for a trial. "I'm not satisfied, I want this to go to court," he reportedly said. The men are expected to be officially charged within days.