Jari-Matti Latvala escaped a late puncture to wrap up victory in Rally Sweden.