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:

[QUOTE=wikipedia]
The majority of deaths, over 4,000, occurred in cities and the suburbs in Hyōgo Prefecture.

One in five of the buildings in the worst-hit area were completely destroyed (or rendered uninhabitable). About 22% of the offices in the central business district were rendered unusable and over half of the houses in that area were deemed unfit to live in. High rise buildings that were built after the modern 1981 building code suffered little, however those that were not constructed to these standards suffered serious structural damage. Most of the older traditional houses had heavy tiled roofs which weighed around 2 tons, intended to resist the frequent typhoons that plagued Kobe, but they were only held up by a light wood support frame. When the wood supports gave way, the roof crushed the unreinforced walls and floors in a “pancake” collapse. Newer homes have reinforced walls and lighter roofs to avoid this, but are more susceptible to typhoons.

The extent of the damage was much greater than in the similar-magnitude Northridge earthquake in Los Angeles, which occurred exactly one year earlier. The difference was in part due to the type of ground beneath Kobe and the construction of its buildings (e.g. many unreinforced masonry buildings collapsed). The immediate population bases of the two areas (Kobe area and San Fernando Valley of Los Angeles) were roughly the same – about 2 million, however only 72 people died in the Northridge quake compared to the more than 6,000 in Kobe.
[/QUOTE]

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.)