Japan has been struck by magnitude 7.0 or greater earthquakes a staggering 46 times since the pagoda at the Horyu-Ji Temple was built in 607AD. So, how did the 122 foot tall structure stay upright through all that shaking?
Multi-story pagoda technology arrived in Japan during the sixth century alongside Buddhism from China. On the mainland, pagodas were traditionally built of stone. However given Japan's seismic instability and higher annual rainfall, that design was simply untenable. But, after much experimentation, Japanese builders figured out how to adapt them to the shaky conditions through three design changes: the use of wide and heavy eaves, disconnected floors, and a shock-absorbing shinbashira.
Japan is a wet country with roughly double China's annual precipitation. So, to keep rainwater from running off building and onto the soil surrounding the foundation, potentially causing the pagoda to sink, builders extended the eaves far away from the walls—constituting up to 50 percent or more of the building's total width. Builders employed a series of cantilevered beams to prop up the massive overhangs. Then, to combat the buildings' severe flammability, the eaves were then laden with heavy earthenware to prevent tinders from igniting the wooden structure underneath.
Side note: Boy are pagodas flammable. The Toji pagoda, Japan's tallest wooden structure, has burned to the ground after being struck by lightning three times since its first building in 824. Fire-by-lightning-strike is actually the primary way that pagodas are destroyed, hence the inclusion of the large metal spire on the roof that acts as a lightning rod. In fact, only two Japanese pagodas in the last 1400 years, the pair at Todai-ji temple, are known to have actually collapsed from shaking alone.
The wide and heavy eaves aren't only good for fire protection, they also act as enormous stabilizers with a huge amount of inertia that must be overcome for the building to begin swaying. And even with the strongest of jolts, the eaves will cause the building to gently sway rather than shake.
The Horyu-ji pagoda doesn't have any central load-bearing beams like you'd see in modern construction. Since the building tapers as it rises, no single load-bearing vertical beam connects to the one below it. The individual floors themselves aren't solidly connected to their neighbors either, just piled atop one another with loose-fitting brackets. This is actually a big advantage in earthquake country. During a shake, the floors will sway in a slithering fashion, with each floor moving in the opposite direction of the ones immediately above and below. This allows the building to more fluidly ride the seismic wave than a more solid building would.
To keep the floors from flexing too far, builders came up with an ingenious solution—the shinbashira. It looks like a large load-bearing column, but it doesn't actually support any of the building's weight (that weight is supported by a network of 12 outer and four inner columns). Built from a large pine trunk, the shinbashira is strung from the underside of the roof and hangs down a shaft in the center of the structure. Sometimes it's buried into the earth, sometimes it rests lightly atop the ground, and occasionally it doesn't even touch the ground—it just freely hangs. The shinbashira acts as a massive tuned mass damper, helping to mitigate the earthquake's vibrations. It also prevents the floors from swaying to the point of collapse and absorbs some of the momentum of the floors as they strike against it. Basically, it's a giant stationary pendulum with enough mass to prevent the lighter floors from freely swinging around.
This same damping technology is still in use today. The The Taipei 101 employs a massive 4-story, 730-ton steel pendulum hung from the 92nd floor to prevent the building from swaying in high winds. The Citicorp Center in New York, uses a 400 ton concrete block to prevent movement during hurricanes.