The High Court in Nairobi has ordered former Interior Cabinet Secretary Fred Matiang'i to deposit Sh200,000 cash bail for his freedom.
Justice Kanyi Kimondo gave Dr Matiang'i anticipatory bail over alleged looming arrest.
He, however, said the police were at liberty to investigate Matiang'i.
"For avoidance of doubt, the first to sixth respondents are at liberty to investigate any criminal conduct by the applicant. However, they shall not arrest or detain him on view of the order 3 above," said Justice Kimondo.
Matiang'i had moved to court seeking anticipatory bail after reports the government plans to arrest him.
In his application, Matiang'i argued that a raid on his home in Karen, Nairobi, was a political witch-hunt by President William Ruto's government.
He told the court that confidential sources had informed him that he was to be arrested by the Ethics and Anti-Corruption Commission (EACC) and charged with abuse of office.
"Through a confidential source, I was reliably informed that the Ethics and Anti-Corruption Commission had also received instructions ... to open a criminal file and charge me with trumped-up charges of abuse of office," he said.
Matiang'i, a powerful minister in former President Uhuru Kenyatta's administration, has lamented that the current government started its assault on him by withdrawing his security. This was before a contingent of police officers raided his home, he said.
The former CS claimed the officers attached to him were withdrawn a day after he spoke at the home of his former Cabinet colleague, the late Prof George Magoha.
"The second respondent (Inspector General of Police Japheth Koome) has already demonstrated malicious intent and a clear disregard for the rule of law by abusing due process as evidenced by the reduction and withdrawal of the security officers assigned to the applicant, thereby exposing him to harm despite the sensitive nature of his last post as a Cabinet Secretary," said Matiang'i's lawyer, Danstan Omari.
The timing of the raid and his alleged looming arrest, Matiang'i said, were meant to ensure that he does not attend his former colleague's funeral.
"The applicant is aware that his woes got worse when he gave a speech at the home of the late Prof Magoha where he shared lessons on public service that he had learnt from Magoha. His security was withdrawn the next day and the impending arrest is part of the scheme to harass and silence him forever," Matiangi's application read in part.
In his supporting affidavit, Matiang'i claims that during his tenure as a Cabinet Secretary, he never had any unanswered audit queries.
Matiang'i has sued Directorate of Criminal Investigations (DCI) boss Amin Mohamed, Koome, Director of Public Prosecution Noordin Haji, EACC, the Independent Police Oversight Authority and the National Police Service Commission.