That gets around countries that consider their postal code database a licensed dataset.
From UI side, I’d probably not autofill, but add autocomplete (e.g. using <datalist>¹). This way you can still have browser autofill the user’s address if saved (do also set the autocomplete² props correctly!), and suggest one or multiple variants you have in your database, and let the user fill it out manually still, without having to find and click “My address isn’t here”.
¹<datalist>: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
(quick note re: compat; Firefox does support it for the text fields, check the table at the bottom)
²autocomplete: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
Include a field for the country that is autofilled via Geolocation API or geoip if that's unavailable.
Or just don’t try to be too clever.
Would be simple enough to have someone type the zip or postal code first, then move the countries that are known to have that zip code to the top of the drop down (still in alphabetical order), and all the other countries below that (also in alphabetical order).
Leave all the fields editable, i.e. the postal code only suggests, ranks, or prepopulates.
Seems like that would handle all the edge cases, including those where a zip code doesn't refer to one and only one city, or where a zip code has changed or been added to a country.