Media playback is not supported on this device
The defender, 35, has been struggling with a hip injury this year and last played on 30 January.
Mackay was the first Saints captain to lift the Scottish Cup, in 2014, and manager Tommy Wright said the player was close to "irreplaceable".
"I'm happy that I've given myself every chance to get back playing but it's not to be," MacKay told the St Johnstone website.
"I've been aware of this issue for the past couple of years and, although the first operation brought about a level of improvement that enabled me to get back playing and feeling fine, there was a gradual deterioration again over a period of time to the extent that I was unable to train.
"A second operation followed which again helped but not to the extent that I feel that I can get back to the fitness levels needed for full-time football.
"The decision hasn't been an easy one but I've had to take into consideration that I don't want to do irreversible damage that affects me away from football.
"I'll obviously miss playing but my decision opens up plenty of other opportunities.
"The club has done everything it could have to help in my recovery and I thank them for that and I thank the fans for their support over the past seven years and assure them I'll be around the club for some time yet."
Mackay, who also played for Dundee and Livingston, has been coaching Saints' under-20s side, which he says he is "thoroughly enjoying".
In total, he made 268 appearances for St Johnstone and Wright said: "It's disappointing news for Dave and the club but ultimately he is still a young man and it's the best decision for him and that's all that matters.
"I could go on all day about what Dave has done for Saints but that is well documented in the club history books.
"The simple truth is that I'm losing a great player and my captain. Very few players can be described as irreplaceable but Dave comes close.
"He'll be missed in the dressing room with his leadership qualities and dry sense of humour and on behalf of myself, my staff and the players we wish him every success in the future."
St Johnstone captain Dave Mackay has announced his retirement from playing.