Nikola Dovedan's late goal secured Heidenheim a second season of Bundesliga football, whilst relegating bottom side Darmstadt.