The spinner has opted to walk away from the sport at the young age of 25 just as his international career was taking flight.
Ansari made his England Test debut in the winter and went on to make three appearances, but he has decided now that he wants to try to fulfil ambitions away from cricket.
The middle-order batsman, who achieved a double first in Politics, Philosophy and Sociology at Cambridge University in 2013, has revealed that he is considering a career in law, insisting that now is the right time for him to pursue it.
In a statement released on Surrey's website, Ansari said: "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. This has been a very difficult decision to make and I have not made it lightly. I started playing for Surrey at the age of 8 and the club has been a hugely important part of my life since then. Surrey have always completely supported me and I am extremely grateful to the club for their backing over the years. It is, therefore, with great sadness that I say goodbye.
"Nevertheless, I have always been clear that when the time was right for me to move on I would, and that time has now come. 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. With that in mind, I am now exploring another career, potentially in law, and to achieve this I have to begin the process now.
"I will look back extremely fondly on playing with some wonderful teams and having the opportunity to perform in front of the best crowds in county cricket at the Kia Oval. Equally, to have played three Test matches for England was a huge honour and it is something I will undoubtedly savour for the rest of my life. Most of all, I will miss the people with whom I have shared my career and I cherish the relationships that I've formed along the way.
"I would like to thank Surrey and its fans for the way they have supported and encouraged me over the last 17 years. I am now looking forward to starting a new chapter in my life, but I know that Surrey will always feel like a home to me."
Ansari earned his first cap for Surrey in 2014.