The home side had eased to a 21-15 half-time lead but were almost shocked by the visitors as they came back to within two points of victory.
Yet Medvedi held on, and will now travel to Germany on April 5 with a superb chance of earning a spot in the semi-finals.
Loewen face uphill task against Kiel
Hamburg edged Flensburg in their quarter-final first leg on Wednesday, while on Sunday Zagreb play Kiel and Ciudad Real take on Veszprem in their quarter-final first legs.
Big guns kept apart
Incredible handball goals at the Olympics