Germany's domestic intelligence chief, Hans-Georg Maassen, has been told to quit and move to a senior post at the interior ministry.
The government decision came amid a row over Mr Maassen's response to far-right unrest in Chemnitz, eastern Germany.
Anti-migrant "hunts" were reported there on 26 August after a German man was killed in a brawl with migrants.
Mr Maassen doubted that foreign-looking people had been hounded. Chancellor Angela Merkel was urged to sack him.
Mr Maassen will leave the BfV spy service and become a state secretary in the interior ministry.
Several xenophobic assaults were reported in the eastern city after the fatal stabbing of Daniel Hillig. They were described as racist "hunts", and images emerged showing demonstrators chasing people and flinging bottles and fireworks.
Controversially, spy chief Mr Maassen said his Federal Office for Constitutional Protection (BfV) - which is similar to the British MI5 - had "no reliable information about such hunts taking place" in Chemnitz.
He also questioned whether a video posted by "Antifa Zeckenbiss" - meaning "anti-fascist tick bite" - really showed, as claimed, a "hunt in Chemnitz" on 26 August.
Mr Maassen said the video could have been disinformation. He said he did not know who was behind Antifa Zeckenbiss.
German public broadcaster ARD said in a "fact-check" that Antifa Zeckenbiss is an anonymous Twitter account, active since February, posting anti-fascist messages and "there is nothing to indicate that it is a fake account".
There were more far-right rallies in Chemnitz after 26 August, and smaller counter-demonstrations by leftists.
Who decided to sack the spy boss?
Tuesday's decision was a compromise between Mrs Merkel and her coalition partners - Interior Minister Horst Seehofer, of the right-wing Bavarian CSU, and centre-left Social Democrat (SPD) leader Andrea Nahles.
Mr Seehofer defended Mr Maassen's actions over Chemnitz, but Ms Nahles wanted him dismissed.
Earlier in the day, an Iraqi man identified as Yousif A was released from custody, after three weeks in detention over the killing of Daniel Hillig.
His lawyer Ulrich Dost-Roxin said the detention had been "illegal", and accused officials and politicians of using him for political ends.
"No witness accused my client of involvement in the crime," he said in a statement.
A Syrian man is still in custody, and police are still looking for a third suspect.