Why did so many die in the Great Hanshin quake?

The Great Hanshin Earthquake struck Kobe, Japan in 1994. It was a magnitude 6.8, and 6400+ people died.

The Loma Prieta Earthquake struck San Francisco, California (US) in 1989. It was a magnitude 6.9, and just 63 people died, 42 of them from a single incident in which a highway overpass collapsed.

The US and Japan are both first-world countries with strong building codes (or so I thought). So why the vastly different body count for these two apparently similar earthquakes?

One factor of course is that the Kobe earthquake epicentre was 20km away from Kobe, population 1.5 million.

Whereas the Lomo Prieta quake’s epicentre was 100km from San Francisco.

The Wikipedia article cited in the OP compares the Hanshin quake to the Northridge quake in the US (not Loma Prieta) and has this to say:

The takeaway: the soil substrate made some of the difference, but a large part of the problem was old, pre-existing buildings not brought up to the modern building code (which had only been promulgated 13 years before the quake.)