Borussia Monchengladbach all but mathematically joined Bayer Leverkusen in qualifying for the Champions League next season after coming from behind to beat their local rivals 2-1 at home.