Wagner took over as Terriers boss in November 2015 and led them to promotion to the Premier League in 2016-17 via the Championship play-offs.
Huddersfield were one of the favourites for relegation last season but Wagner kept them up with a 16th-place finish.
They have struggled this season, with just 11 points from 22 games, and are eight points adrift of safety.
“The 47-year-old leaves Town after detailed discussions with the board of directors, with both parties agreeing this is the correct move for the future of the club,” Huddersfield said in a statement on their website.
Huddersfield said the decision had been reached by mutual consent after the German held discussions with the board.
“I know the term ‘mutual consent’ is often a byword for the manager being sacked in professional football but this is a truly joint decision.
“David has a real, genuine love for this club and, like me, his foremost concern in our talks has been to establish what is best for Huddersfield Town,” the chairman, Dean Hoyle, said.
Wagner took Huddersfield into the Premier League and kept them up against the odds last season but the team have collected only 11 points from 22 games this season, with a lack of goals particularly problematic. The sequence of defeats ended with a goalless draw at Cardiff on Saturday but Wagner has departed nonetheless.
“I had no intention of sacking David this season,” Hoyle said. “Subsequently David – being the great man he is – came to us and made it clear that he needs a break from the rigours of football management.
“We discussed making that change immediately but he also made it clear that he would give his all for the rest of this season before departing in the summer if we preferred. After a long discussion we all felt that David staying at the club until the end of the season was best but we’ve kept discussions open and we all now feel that the time is right to part ways.”
Hoyle paid tribute to Wagner, who earned Huddersfield top-flight status for the first time since 1972. “Under David’s management, we took this club to the highest position it has held in almost 50 years and created memories that will last forever,” he said.
“His achievements will rightly put him up there in Huddersfield Town history alongside great names like Herbert Chapman and Mick Buxton; legendary managers who changed the face of this club.”
Coach Mark Hudson is due to take charge for Sunday’s game at home to Manchester City.