The former Manchester United and West Brom goalkeeper previously hung up his boots after leaving Watford at the end of the 2021/22 season.
However, he made a return to the game by signing for Wrexham towards the end of last season.
Foster helped them secure promotion to League Two and has made 12 appearances since signing, but has now called it quits.
His decision came after he conceded five in the 5-5 draw with Swindon on Saturday, making it 13 in just four league games this season.
In a statement on Wrexham's website, the 40-year-old said: "The honest truth is that my performances this season haven't reached the level I demand of myself and I feel that now is the right time to retire.
READ MORE ON BEN FOSTER
Aston Villa aim brutal dig at Wrexham and Ben Foster for comment on TikTok
Ben Foster played key role in connecting Nathan Bishop and Paul Mullin after horror clash
"At the forefront of my mind when making this decision, was not only what was best for me but also the Club, and making the decision now gives the Club every opportunity to assess their options before the window closes.
"Wrexham will always have a special place in my heart."
Speaking on social media, he added: "I think the timing is right, I feel sometimes you've just got to be brutally honest with yourself and just admit you can't really do what you used to do.
"It's a shame but I think being 40-years-old, it's kind of expected as well. I feel like there's probably been four or five goals already this season that I should be saving."
Most read in EFL
'Never leave early' - Reynolds and McElhenney react to ten-goal Wrexham thriller
Ex-Arsenal star Aaron Ramsey rolls back years with screamer but Chelsea loanee steals show
Che Adams gives Southampton fans possible parting gift amid Everton transfer pursuit
Leeds fans mock Wilfried Gnonto transfer request with crying baby banner
Wrexham co-owner Ryan Reynolds paid tribute to his efforts on X: "He built memories I'll never let go of for as long as I live. I love this guy. Thank you for everything, Ben."
Manager Phil Parkinson said: "Ben has been the model professional while at Wrexham and has done everything we have asked of him.
"It takes a big person to make the decision he has and one who really understands this Football Club, with the timing of his decision.
"I am sure I speak for everyone, when thanking him for his contribution that went far beyond that one magnificent penalty save against Notts County to help us gain promotion last season.
"Wrexham AFC was a better place for having Ben Foster around the Club."
Foster spent his youth career at Racing Club Warwick before signing for Stoke in 2001.
He would go on loan at Bristol City, Tiverton Town, Stafford Rangers, Kidderminster Harriers and Wrexham during his time at the club.
United came calling in 2005 and he went on to make 23 appearances, winning two League Cup titles.
Foster joined Birmingham City in the 2010/11 and went on loan to West Brom in the following campaign before singing permanently.
He featured 223 times across eight seasons and was named as the club's Supporters' Player of the Season on four different occasions.
In 2018 he returned to Watford after initially going on loan there twice during his spell at United.
After four years at the club, he first announced his retirement from football following the expiration of his contract at the Hornets.
Read More on talkSPORT
Fans notice awkward moment between Bronze and Infantino at World Cup medal ceremony
Klopp appears to tell Liverpool fans 'stop singing that s***' as Anfield belts out song
However, after rejecting a move to Newcastle, Wrexham announced his signing on a short-term contract in March,
Foster was key in their National League triumph and signed a new one-year deal in June, although he has now cut that short.