Mieko Terada moved to Tama in 1976, about the same time as everyone else there. Back then, the fast-growing city in Tokyo's suburban fringe was busy with young married couples and children. These days, the strip of shops where Terada runs a cafe is deathly quiet, her clientele elderly. The people of Tama and their apartments are all growing old and decrepit at the same time, she said.

In the mid-1990s Japan had a smaller proportion of over-65s than Britain or Germany. Thanks to an ultralow birthrate, admirable longevity and a stingy immigration policy, it is now by far the oldest country in the OECD. And senescence is spreading to new areas. Many rural Japanese villages have been old for years, because young people have left them for cities. Now the suburbs are graying, too.

Between 2010 and 2040 the number of people 65 or older in metropolitan Tokyo, of which Tama is part, is expected to rise from 2.7 million to 4.1 million, at which point one-third of Tokyo residents will be old. In Tama, aging will be even swifter. The number of children has already dropped sharply: its city hall occupies a former school. Statisticians think the share of people older than 65 in Tama will rise from 21 to 38 percent in the three decades to 2040. The number of over-75s will more than double.

Tama's inhabitants have already been spooked by an increasing number of confused old people wandering about. By 2025, officials in Tama predict, almost one in four elderly residents will be bedridden and one in seven will suffer from dementia. And the city is hardly ideal for seniors. It is built on steep hills, and the five-story apartment blocks where many residents live do not have elevators.

For Tama, though, the most worrying effects of aging are fiscal. Two-thirds of the city's budget goes on social welfare, which old people require lots of. They do not contribute much to the city's coffers in return. Although Japan's central government redistributes money between municipalities, much of what local governments spend comes from local residency taxes, which fall only lightly on pensioners. In short, said Shigeo Ito, the head of community health in Tama, it pays for a place to avoid growing too old.

So, as well as providing more in-home care, Tama is once again trying to lure young families. With a developer, Brillia, it has already razed 23 five-story apartment blocks and put up seven towers in their place. The number of flats in the redeveloped area has almost doubled, and many are larger than before. That has attracted new residents; although the 430-square-foot apartments in the old blocks were sufficient for the postwar generation, modern Japanese families demand more space. Tama's authorities intend to transform other districts in a similar way.

This is smart policy, but there is a problem with it. The number of 20- to 29-year-olds in Japan has crashed from 18.3 million to 12.8 million since 2000, according to the World Bank. By 2040 there might be only 10.5 million of them. Places like Tama are therefore playing not a zero-sum game but a negative-sum game, frantically chasing an ever-diminishing number of young adults and children. And some of their rivals have sharp elbows.

Follow the Tama River upstream, into the mountains, and you reach a tiny town called Okutama. What Tama is trying to avoid has already happened there. Okutama's population peaked in the 1950s as construction workers flocked to the town to build a large reservoir that supplies water to Tokyo in emergencies. It has grown smaller and older ever since.

Today 47 percent of people in the Okutama administrative area — the town and surrounding villages — are 65 or older, and 26 percent are at least 75. Residents in their 70s outnumber children younger than 10 by more than five to one.

And Okutama's residents are as stubborn as they are long-lived. Some of its outlying villages have become so minuscule that providing them with services is difficult, said Hiroki Morita, head of the planning and finance department. It would be better for their residents, and certainly better for the local government, if they consolidated into larger villages. But old people refuse to leave their shrunken hamlets even during heavy snowstorms and are unlikely to move permanently just to make a bureaucrat's life easier. The internet and home delivery help them cling on.

A building once occupied by a junior high school, which closed for lack of pupils, is becoming a language college. Jellyfish, an education firm, will use it to teach Japanese to young graduates from East and Southeast Asia. It hopes to enroll 120 students, plus staff, which ought to make a notable difference in a district where there are now fewer than 350 people in their 20s.

Copyright 2013 The Economist Newspaper Limited, London. All Rights Reserved. Reprinted with permission.