KANAZAWA, Japan—Because demographics are supposed to be destiny, Japan was long ago consigned to stagnation with its aging population and rock-bottom birthrate.

But in recent years Japan has defied destiny. Since 2012, its working-age population has shrunk by 4.7 million, yet the number of people working has surged by 4.4. million, the critical ingredient in what is now Japan’s second-longest economic expansion since World War II. The proportion of the population in the labor force has risen sharply since 2012, by more than...