He looks certain to be named in Australia's squad for the World Cup in West Indies and the United States
Ansari played in England's Test series in India and Bangladesh last year and also represented the side in an one-day international in 2015.
"After seven years as a professional cricketer and almost two decades in total playing the game, I have decided to bring my cricket career to an end," Ansari said in a statement.
"While the timing may come as a surprise, I have always maintained that cricket was just one part of my life and that I have other ambitions that I want to fulfil."