Kenyan MPs have approved a motion to leave the International Criminal Court (ICC) following an emergency debate.
A bill to this effect is expected to be introduced in the next 30 days, after opposition MPs boycotted the vote.
The ICC has charged President Uhuru Kenyatta and Deputy President William Ruto with crimes against humanity, which they both deny. Mr Ruto's trial is due to start in The Hague next week.
The ICC said the cases would continue even if Kenya pulled out.
The charges against both Mr Kenyatta and Mr Ruto stem from violence that broke out after disputed elections in 2007, in which more than 1,000 people were killed and 600,000 forced from their homes.
Mr Kenyatta is to go on trial in November.
'Defend Kenya's sovereignty'
They were on opposite sides during the 2007 election but formed an alliance for elections in March this year, and analysts say the ICC prosecutions bolstered their campaign as they portrayed it as foreign interference in Kenya's domestic affairs.
The BBC's Gabriel Gatehouse reports from the capital, Nairobi that even though the vote does not halt the cases, it sends a powerful signal of defiance to The Hague - a sentiment that is becoming increasingly popular, in Kenya and across much of Africa.
No other country has withdrawn from the ICC.
Kenya's parliament is dominated by the Jubilee coalition formed by Mr Kenyatta and Mr Ruto.
The motion, tabled by majority leader Adan Duale, said the pair had been "lawfully elected" and the government should take steps to "immediately" withdraw from the Rome Statute, which established the ICC.
The sentence stating that Kenya would "suspend any links, co-operation and assistance" to the ICC was removed during the debate.
Mr Duale noted that the US had refused to sign the Rome Statute to protect its citizens and soldiers from potential politically motivated prosecutions.
"Let us protect our citizens. Let us defend the sovereignty of the nation of Kenya," Mr Duale is quoted as saying.
MPs from the opposition Coalition for Reforms and Democracy (Cord), led by former Prime Minister Raila Odinga, walked out of the debate, calling the motion "capricious" and "ill-considered".
Kenya's withdrawal would not bring "honour to the nation and dignity to our leaders", Cord said in a statement.
"Kenya cannot exist outside the realm of international law," it said.
ICC spokesman Fadi El Abdallah told the BBC's Newsday programme that Kenya's withdrawal would have no bearing on the cases against the two men.
"A withdrawal has an effect only for the future and never for the past," he said.
If Mr Kenyatta and Mr Ruto failed to co-operate, ICC judges "may decide to issue arrest warrants against these accused", Mr Abdallah added.
Amnesty International said the parliamentary motion was the latest in a series of "disturbing initiatives to undermine the work of the ICC in Kenya and across the continent".
"Amnesty International calls on each and every parliamentarian to stand against impunity and reject this proposal," said Netsanet Belay, the group's Africa programme director, in a statement.
Our reporter says that the withdrawal still has to pass at least one more parliamentary hurdle, and could take a year or more to come into effect.
Both Mr Kenyatta and Mr Ruto have repeatedly called for the cases against them to be dropped, saying the charges are politically motivated.
The ICC has refused and says it pursues justice impartially.
In May, the African Union accused the ICC of "hunting" Africans because of their race.
The ICC strongly denies this, saying it is fighting for the rights of the African victims of atrocities.
The ICC was set up in 2002 to deal with genocide, crimes against humanity, war crimes and the crime of aggression.
The court has been ratified by 122 countries, including 34 in Africa.
- 8 February 2013
- 27 May 2013
- 7 January 2015
- 27 November 2017
- 25 June 2015
- 12 December 2011