The 33-year-old curled a 25-metre free kick into the top corner in the 58th minute to cancel out Josip Drmic's first-half goal for Zurich but pulled a muscle in doing so and was substituted to a standing ovation five minutes later.
"It's typical of my career that I scored that goal, as I've often had the fortune to find a goal at the right moment," Frei told reporters.
Frei had intended to play until the end of this season but brought his retirement forward after accepting a post of sporting director FC Lucerne, who are battling relegation
"Only a great player can score a free kick at a moment like that," added coach Murat Yakin.
Frei joined Basel, the club where he began his career, in 2009 after four seasons at Borussia Dortmund and has scored 108 goals for them since then.
Leaders Basel have won the Swiss Super League in every season since his return with Frei finishing as the league's top scorer in the last two.
He scored 42 goals in 84 appearances for Switzerland, including at two World Cups and two European championships, but ended his international career in 2011 following criticism of some of his performances.
A Fabian Schaer penalty and Mohamed Salah goal in the last five minutes gave Europa League semi-finalists Basel the win, extending their lead in the table to three points over Grasshoppers as they chase a fourth successive title.
Grasshoppers could manage only a 1-1 draw at home to Sion while Young Boys, who fired coach Martin Rueda last week, lost 2-1 at home to FC Thun in their first game under replacement Bernard Challandes.
- Sports & Recreation