Sverige tog ett stort steg mot semifinal i handbolls-EM genom att besegra Portugal med 40–33 efter storspel av målvakten Tobias Thulin.