For China's top leaders, the unrest seemed like a recurring bad dream. Last Saturday 20,000 furious Chinese protesters shouting "Japanese pigs, come out!" rampaged through Shanghai, tossing stones and tomatoes at the Japanese Consulate, trashing shops and flipping over a Nissan van. Two Japanese were reported injured by an angry mob; smaller demonstrations broke out in Hangzhou and Tianjin. The previous week, thousands of unruly Chinese in Beijing had broken windows at the Japanese Embassy. Just hours afterward, China's powerful Politburo Standing Committee called an emergency damage-control meeting. President Hu Jintao warned against letting the unrest spread, to avoid giving protesters "a pretext to vent their dissatisfaction" over other issues, according to a high-level Chinese source. The mood of alarm evoked the Politburo strategy sessions back in 1989, added the source, when massive protests paralyzed Tiananmen Square for weeks. "They don't want to lose control."

The immediate cause of the protests--which seemed to receive some official encouragement--was the publication in Japan of revised junior-high-school textbooks that, the Chinese claim, whitewash Tokyo's World War II record. But the simmering Japan-China dispute is not really about the war. Japan insists that it has apologized for its wartime atrocities, and has given China some $34 billion in development aid that is war reparation in all but name--a fact seldom mentioned in the Chinese media. Rather, the two rivals are engaged in an increasingly vitriolic struggle to dominate the economic, diplomatic and military future of Asia. China, flush with pride and power after 20 years of pell-mell economic growth, is spending heavily on its military and flexing its newfound diplomatic muscle. Japan, nervous about China's rise, is shedding the pacifism that has anchored its foreign policy since the end of World War II.

Both nations are competing to secure new energy supplies--especially potentially large gas deposits in the East China Sea, which the Japanese media have dubbed "the sea of conflict." Last week Japan's Trade Ministry announced it would allow Japanese firms to start drilling for oil and gas in the area--a move that China, already engaged in exploratory activities there, called a "serious provocation." And each country seems almost eager to thwart the strategic ambitions of the other, even as bilateral trade between the two has skyrocketed. China is trying to sabotage Japan's aim to become a new permanent member of a revamped United Nations Security Council. Japan is impeding China's bid to become a member of the Inter-American Development Bank. "Psychologically and strategically, both countries are becoming locked into a nasty relationship," says Washington, D.C.-based Sinologist Minxin Pei. "When we look back, this will be seen as a turning point in Sino-Japanese relations."

The friction is emblematic of a larger phenomenon. There's been a surge in what some are calling a new nationalism throughout East Asia. It's evident in the ways that countries are now asserting their interests--and challenging those of their neighbors. South Korean President Roh Moo Hyun is appealing to nationalist sentiment to shore up his shaky political support, while in Taiwan, a new generation of politicians is encouraging a more assured sense of Taiwanese identity. Since 1992, the number of island residents identifying themselves solely as Taiwanese--as opposed to Chinese or Chinese-Taiwanese --has more than doubled, from 18 percent to 40 percent of the population. "Our world view has changed," says Chang Mau-kuei of the Taipei-based Institute of Sociology at the Academia Sinica. "Now Taiwan is at the center of it, not China."

National pride is nothing new in East Asia, of course. But in the past it's been rooted largely in historical grievance--a defensive reaction to imperialism and the horrors of war. David Kelly, a research fellow at the National University of Singapore's East Asia Center, notes that "historical reservoirs of feeling cannot be underestimated." But, he adds, "the new nationalism is rooted more in the aspirations of younger people, who've grown up under conditions of peace and prosperity. Part of the urban-middle-class identity nowadays is nationalistic. You want the Olympics, for example."

For the past 30 years, East Asia has been preoccupied with its economic development. During that period, politicians in Korea and China would get worked into a lather by controversies over revisionist Japanese textbooks, "comfort women" or, more recently, visits by Japanese prime ministers to the Yasukuni Shrine, the country's infamous war memorial. But by and large everybody was busy striving to raise standards of living; there wasn't much time for chest-thumping.

That's no longer the case. For today's cosmopolitans--the young, the educated, the tech savvy--the message of economic stability no longer resonates quite as loudly as it did in the 1970s and 1980s. They've got money, leisure time and opinions--and, thanks to newfound social freedoms and the Internet, they are aggressively expressing their views. Those attitudes are increasingly driving government policy. Public opinion, for example, underlies Beijing's hard-line position on Taiwan. A grass-roots Chinese online petition to keep Japan from becoming a permanent U.N. Security Council member has gathered 22 million signatures.

One of the biggest nationalist groups in China today is the Patriots' Alliance, started on the Internet by a group of middle-class urban professionals, including a 29-year-old Web designer named Lu Yunfei. Its Web site claims 76,000 registered members. When Beijing awarded a prime contract for a new railway- construction project to a Japanese company, the Patriots' Alliance organized an opposition campaign, gathered 86,000 electronic signatures and scuttled the deal, at least for now. So far in April, Netizens' calls to protest have triggered unrest in eight Chinese cities--the biggest demon-strations since 1999, when protesters trashed the American Embassy after the Chinese Embassy in Belgrade was bombed by U.S.-led NATO forces.

In itself, a certain degree of nationalist spirit isn't necessarily a bad thing in a stressed and fast-changing society. It's when nationalisms collide that dangers arise. And the dangers are potentially explosive in East Asia, where--in stark contrast to "postnational" Western Europe--there are no overarching structures like the European Union or NATO to dampen tensions or provide a framework for cross-border cooperation. The region abounds in unresolved territorial disputes--four of them involving Japan, the one country whose historical record still inspires suspicion and fear among its neighbors.

China-Japan relations have been increasingly acrimonious since last November, following a military encounter on the high seas. Japan's Self-Defense Force detected a submerged Chinese nuclear-powered submarine lurking in its waters, not far from natural-gas fields that both sides are racing to exploit. The Japanese pursued the sub for two days and demanded an apology, which the Chinese gave. "What's notable wasn't the Chinese sub's presence, but the fact that the confrontation-averse Japanese chased it away," says Adam Segal, a China analyst with the U.S.-based Council on Foreign Relations.

Around the same time, Japan adopted a tougher stance toward its rival. First, Japan issued a defense white paper specifically naming China as a military threat. Then on Jan. 19, in an unprecedented joint statement, Japan and the United States declared, in essence, that Taiwan's current de facto independence was a "common strategic objective." Prime Minister Juni-chiro Koizumi's cabinet includes a number of right-wing conservatives sympathetic to Taiwan. Japan also sided with the United States against moves to lift the European Union's 16-year-old arms embargo against China.

Since his election in 2001, Koizumi has made restoring national pride a key component of his effort to reform Japan's stagnant political system. Younger Japanese, in particular, have embraced his ideas. Beijing strategists believe Tokyo has been emboldened by a conservative, hawkish U.S. administration, which is beginning to focus on the coming "China threat." Mainland leaders didn't exactly help their case when the Chinese Parliament pushed through a tough antisecession law in March, aimed at deterring Taiwanese moves toward separatism. The legislation simply heightened sympathies for Taipei and made Beijing seem all the more belligerent.

But insecurity, not just pride, is also driving Japanese nationalism. "Japan's place in the pecking order is at risk," says Jeffrey Kingston, a professor at Temple University in Japan. "China is now threatening to outpace Japan." The lost decade of the 1990s, when Japan seemed to relinquish its status as Asia's most dynamic economic power, has left the younger generation deeply uncertain--with some finding solace in dreams of national greatness propagated by figures as diverse as the populist governor of Tokyo, Shintaro Ishihara, or the manga artist Yoshinori Kobayashi, whose books overturn the idea of Japanese war guilt.

The Beijing regime has insecurities, too. Pandering to grass-roots nationalism helps compensate for its own lack of legitimacy. Marxism is dead as a motivating ideology, and its successor, "money worship," has spawned frustration over the yawning gap between rich and poor. Targeting Tokyo is a default position for the Chinese Communist Party, which grew popular in the 1930s due to its firm anti-Japanese stand.

China and Japan, though, have good reason to defuse the tension. Bilateral trade between the two countries now exceeds $200 billion annually. Last year China surpassed the United States to become Japan's top trading partner. Japanese firms have invested huge sums in China, and employ an estimated 1 million Chinese. The two economies "have become so interdependent and so complementary that we don't have the freedom to keep our distance," says Hatsuhisa Takashima, a Foreign Ministry spokesman. "We have to keep these very important relations intact." True, but there hasn't been a top-level summit between the leaders of Japan and China since 2001. Both Hu and Koizumi will attend the Asia-Africa summit in Jakarta in late April, but it's not known if they plan to meet.

Experts doubt that the china-Japan feud will escalate into any sort of military confrontation. But a mainland attack or blockade against Taiwan--a continuing wild card--remains a worry. And Beijing's rapid military modernization has already sparked concerns of a regional arms race. China's Navy, in particular, is much more impressive than it was even five years ago, having acquired 23 new amphibious assault vessels and 13 attack subs. Last December Beijing launched its first in a new class of nuclear-powered subs--years earlier than anticipated by the U.S. intelligence community. China is also building its own diesel-electric submarines.

Nationalism, once unleashed, is not easy to control. Last week Netizens called for a massive anti-Japanese march through Tiananmen Square on May 4, the anniversary of a 1919 student movement protesting the Chinese government's humiliation by Japanese demands after World War I. Still haunted by the specter of 1989, the leadership won't likely permit any grassroots demonstration in the square. But if anti-Japanese marchers feel thwarted by police, they could easily turn their anger against the government for kowtowing to Tokyo. And then China's Politburo will be holding a lot more crisis meetings in weeks to come.