Alfredo Morelos' first-half goal looked set to be enough to claim all three points for Rangers – a win which would have seen them top Group G.
But an 89th-minute Borna Barisic own goal set up a nervy finale at Ibrox on Thursday.
However, despite losing Ryan Jack to a second yellow card in stoppage time, Rangers held firm to book their place in the round of 32, with Porto - who won 3-2 against Feyenoord – topping the table.
After a dominant start, Rangers hit the front when Morelos – who missed a penalty in Sunday's Scottish League Cup final defeat to rivals Celtic – tucked in his 26th goal of the season.
The 23-year-old had already drawn a smart stop from Von Ballmoos before getting the better of defender Frederik Sorensen to slot home.
Morelos could have doubled his tally shortly after the restart, but Von Ballmoos did well to close the angle.
That miss lifted the visitors and Allan McGregor had to make an instinctive save from Christian Fassnacht's header, before Morelos saw another strike well saved.
Young Boys made their good fortune count – Barisic only able to turn a low cross into his own net – but Rangers clung on, even when down to 10 men following Jack's dismissal.