"My journey has seen many ups and downs but I am feeling satisfied that I am leaving on my own terms," Afridi wrote on Twitter.
The 34-year-old Afridi, who quit Tests in 2010, said the decision was "hard" but he decided to leave with an eye to the future of the team.
"My 18 years' dream dedicated to Pakistan. First ever player (respect) to have taken such a hard decision but (it) will pave way for many new talents."
Afridi, who captained the national team to the semifinals in the 2011 World Cup, has played 389 ODIs since hitting the fastest century (off 37 deliveries) on his debut in October 1996 against Sri Lanka in Nairobi. The record stood for more than 17 years before New Zealand's Corey Anderson broke it in January this year.
"I am happy about my achievements and records but the only regret I have is losing fastest ODI century record," he said.
He has scored 7,870 ODI runs at an average of 23.49 and a strike-rate of 116.29. He has also taken 391 wickets, the sixth-highest in ODIs, at 33.89 and an economy-rate of 4.62.
"Thank you so much for all your support and prayers throughout my ODI career ... it means alot to me ... love you all!"