Frei, who is quitting international football at the end of the season, was given a standing ovation when he was substituted in the second half, a stark contrast to the jeers he received in two home games earlier this season.
Olexandr Alijev and Yvgeni Konoplianka replied as Ukraine twice came from behind at a half-empty Stade de Geneve.
Switzerland went ahead five minutes before the break when Frei floated a free kick into the top corner - his first goal for Switzerland since the World Cup qualifier in Latvia in September last year.
Ukraine levelled quickly after the break with a Olexandr Alijev free kick which was deflected into the goal off the back of his team-mate Andriy Yarmolenko.
The hosts went ahead again just after the hour mark when Frei slid in unmarked at the far post to turn in Hakan Yakin's free-kick for his 42nd goal in 82 appearances.
However, Ukraine's Konoplianka had the last laugh, scoring with a vicious dipping shot from the edge of the area.
Frei, 31, was jeered after missing a penalty against Australia in August and also in the 4-1 Euro 2012 qualifier win against Wales last month. He said he had wanted to quit immediately but was dissuaded after receiving letters of support from fans.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.