Matt Green scored the only goal of the game from the penalty spot at Field Mill after Louis Briscoe was tripped by Glen Little in the area as the Stags secured their return to the fourth tier of English football after a five-year spell as a non-league side.
David Artell was sent off for the Welsh side in the final minute of the game for a poor challenge on Colin Daniel but they can still secure promotion via the play-offs.
Wrexham will face Kidderminster in the semi-finals of the play-offs after Harriers had to settle for second spot in the league despite defeating Stockport 4-0 at Aggborough in a game marred by violent scenes.
A number of Stockport supporters came on to the field of play after Anthony Malbon had given Kidderminster the lead in the 51st minute.
The fans confronted players from both teams, forcing referee Michael Bull to take the sides from the pitch for safety reasons.
Malbon scored again soon after the game was restarted and further strikes from Cheyenne Dunkley and Martin Devaney sealed the victory for Harriers as County were relegated.
Even a victory would have not have been enough to keep them in the league though, after results elsewhere went against them.
Meanwhile, Newport will face Grimsby in the other play-off semi-final, with the Mariners given a confidence-boost going into that tie after they beat their Welsh opponents 3-0 at Blundell Park.