Netley Common-based Riley, 46, had been in pole position to replace Stuart Ritchie at the Testwood Stadium helm after parting company with Bashley earlier this week. He has signed a two-year contract with the Stags.
Having previously played for Bash, the former Navy PTI returned to the New Forest club as player-coach in August 2005 and took control two months later.
He masterminded the club’s surge to the Evo-Stik Division One South & West championship in 2007 and has kept them in the Premier Division ever since, reaching the play-off semi-finals in 2008.
He takes over a talented Totton side who, in their first season as a Southern Premier club, finished runners-up to Oxford City in the play-off final and reached the second round proper of the FA Cup for the first time in club history.
Former AFC Bournemouth trainee Ferrett was Riley's player-coach and right-hand man at Bashley, having previously played as a left winger/full-back for the likes of Havant, Basingstoke, Dorchester and Salisbury.
Riley said: “I’m really looking forward to working with the chairman (Paul Wallace)and his team behind the scenes and I’m relishing the opportunity that has come my way, which is a very exciting and fresh challenge.
“Having witnessed the atmosphere at the fantastic Testwood Stadium and the passion of the travelling fans, I believe there are exciting times ahead for AFC Totton.
“I also believe that Chris and myself can add our own ideas in an effort to build on the club’s achievements last season.
“The work that we will both undertake over the next few weeks will be vital in order to ensure that some of the uncertainty that has surrounded the club since the end of the season, including player retention, can finally be resolved.”
Totton are planning a fans’ evening to formally welcome the pair to the Testwood Stadium.