On a windy autumn night, dried leaves scuttled across a deserted courtyard and paper lanterns swayed in the chill breeze, casting a pale yellow light on the facade of a 300-year-old Shinto shrine.

Into this eerie scene stumbled a tipsy Tokyo office worker. Bowing his head, he hurled a handful of coins at a collection box and clapped his hands together to summon the spirit of a Japanese warrior who had been dead for a thousand years.

"I've been coming here since I was 10 years old," said the man, who refused to give his name and looked to be in his late forties. "This is the shrine of my family's patron god, but if I told you what I was praying for, it would spoil the effect."

That god is Masakado Taira, a local warlord who lost his head to the emperor's army in 940 after a bloody battle for control of the great Kanto Plain, where today Tokyo is located. This sacred spot in Kanda, one of the city's oldest districts, is dedicated to the peaceful repose of his vengeful soul.

To many foreigners, such beliefs may seem out of place in a Japan with a booming industrial economy. But hundreds of well-kept shrines and temples honoring the memory of fallen heroes and heroines dot Tokyo's congested cityscape.

Here, thousands of Tokyo's residents call on the spirits each day and night, with prayers for help with family troubles, success in business, good health and protection from accidents in the city's snarled traffic.

During O-Bon, Japan's yearly Festival of the Dead, which may be considered the equivalent of the American Halloween, many of the city's 12 million people flock to places like Kanda to offer rice and sake to the gods and to take part in traditional dances and songs aimed at appeasing the souls of their ancestors.

What gives the Japanese a healthy respect for the dearly departed, said Keisuke Nishimoto, an authority on the nation's vast supernatural folklore, is that "we believe the world of the spirits is only a very small step from our human world. The spirits must be properly treated because if they are left to ramble around between heaven and the here-and-now they can do many nasty things."

Japan's feverish postwar economic growth has helped push the country's spiritual legacy into the background and most of today's trendy younger generation consider it unfashionable to express open belief in the supernatural.

But the hair-raising tales of ghosts and goblins, once passed down the generations in the glow of the family charcoal brazier, are now kept alive by a multimillion-dollar business, which churns out a constant flow of films, television plays and bestsellers that cater to the nation's appetite for the macabre.

The theme of revenge is the key to such stories, which date from the days of Edo, as Tokyo was called before the end of Japan's feudal period in the 1860s. They tell of the restless spirits of proud samurai warriors and faithful women jilted by husbands and lovers who return to wreak havoc on their earthly foes and still exert a powerful pull on the imaginations of Tokyo's sophisticated city dwellers. They also reflect a rich part of the old capital's history.

Amid the towering glass-and-steel structures of the city's downtown business district in Otemachi, a tiny Japanese garden with a stone tablet marks the spot where, according to legend, Masakado's head came to rest after a spectacular flight from his enemies' grip through the thundering heavens.

To the frustration of Tokyo real estate developers, the 300-square-meter patch of ground -- worth an another-worldly $10 million in Tokyo's market -- has remained untouched because of a widespread belief that tampering with it would rekindle the ancient rebel's fury.

In 1603, shogun Ieyasu Tokugawa ordered the shrine built at Kanda on the northeastern approach to his castle, which dominated the center of old Edo and where Emperor Hirohito lives today.

Traditionally, the forces of evil were thought to enter from that direction and the shoguns led their samurai retainers in an elaborate procession each year to enlist Masakado's support in providing the first line of spiritual defense beyond the castle moat.

While not all of Tokyo's hallowed spots are dedicated to such major historical figures as Masakado, most of them are maintained to placate the souls of the ancestors. The huge Yasukuni Shrine in central Tokyo is devoted to appeasing the spirits of 2.4 million Japanese soldiers, most of whom were killed in World War II.

In Yotsuya, the place where Tokugawa's troop of warrior-magicians, or ninja, were quartered, a Buddhist temple now watches over the spirit of Oiwa-san, Japan's most famous female ghost.

According to legend, this unfortunate lady was poisoned by her philandering samurai spouse and his lover in the late 1600s. The story, the subject of a Kabuki play still performed here each year, tells of her return from beyond the grave to seek revenge by driving her husband mad.

Kyojun Nakajima, the temple's priest, said the actors routinely come to pay their respects to Oiwa-san to prevent her wrath for summoning her unhappy spirit back to the stage.

Nakajima has about 2,000 visitors each year who come to pray for Oiwa-san's help in settling family disputes. Reflecting a growing generation gap in Japan, he said, "Before the war most people came here when they had problems with their husband or wife. Now they are parents who have trouble with their children. Mainly, they don't want their families destroyed."

According to Tatsuzo Endo, a leading local merchant who heads the Masakado Preservation Society, previous attempts to shun tradition have met with hard luck.

In the late 1930s, Japan's military rulers outlawed the colorful festival held each September for centuries to honor the popular hero. Instead, they insisted, the money for the event should be funneled into the war effort in China.

In 1940, he recalled, the Ministry of Finance, then built on a nearby site, burned down during a thunderstorm and "people said it was the revenge of Masakado."

In the early postwar years, American occupation forces brought in bulldozers to pave the area for a parking lot. Two Japanese workers were killed on the job, prompting an American officer to call in Endo's father to explain the legend.

"The interpreter was very poor," said Endo, whose family has lived in Tokyo for 400 years, "so my father had to explain very simply that this was the home of a very big chief, like among the American Indians. The officer got the message and decided to spare the place."

In the mid-1960s, Mitsui, Japan's giant trading conglomerate, bought the adjacent property for the construction of its 24-story world headquarters. A rash of serious accidents and a tangled legal dispute halted work on the project for several years before Mitsui decided to spend $75,000 to rebuild the Masakado memorial.

One top Mitsui executive suggested that the company views the sizable annual bill for carefully tending the spot as something of an insurance policy with the powers in the great beyond.

"From the standpoint of our spiritual health," he said, "we cannot afford to contradict tradition."

Inside Mitsui's offices, each desk is positioned so that none of its 6,000 employes will be forced to sit with their backs disrespectfully displayed to Masakado's stone marker.

Earlier this year, Mitsui President Toshikuni Tahiro called on Masakado's larger shrine in Kanda, the official said, to pray for help in Iran where the political turmoil has stalled work on the company's $6 billion petrochemical plant project.

"None of this can be proved by modern science," Endo said, "but for many centuries people have held to such beliefs, and it is only natural that they have carried over til today."

Originally, Masakado's popularity, he said, stemmed from the fact that his rebellion "offered hope to people who suffered from the evils of politicians, heavy taxes and cruel treatment at the hands of the government."

Ancestors of today's Tokyo residents organized festivals in his honor "so that they could let off steam. Things haven't changed. People still talk about Masakado's revenge, and politicians here are basically the same as they were a thousand years ago."