Religion and politics
Shinto and nationalism

Japanese flags ©
Shinto can't be separated from Japan and the Japanese, but in the late 19th and first half of the 20th centuries Shinto became an established state religion, inextricably linked to the cause of Japanese nationalism.
The link between Shinto and nationalism
Shinto legend tells that the emperors of Japan are descended in an unbroken line from the first Emperor, Jimmu Tenno, Amaterasu-Omikami's great-grandson. The native Japanese people themselves are descended from the kami who were present at the founding of Japan.
This story contains a very clear message that Japan is an old country, whose people are descended from the founding kami, and an Imperial family with an unbroken line of descent from Amaterasu herself. The Imperial family is older than the people of Japan, and descended from a kami of higher rank.
The political message of the story is that Japan is the way it should be, that its survival depends on maintaining the relationship between the Emperor and his people, and that the Emperor rules Japan because the gods want him to. Before the Meiji Restoration and the creation of State Shinto, this story was just one myth among many, and not something crucial to Japanese self-image.
Religion and politics
In the 6th century Buddhism was imported into Japanese religious life and Buddhism and Shinto together began to play a part in Japanese government. The Emperor and court had to perform religious ceremonies to make sure that the kami looked after Japan and its people. A court liturgical calendar was developed.
Over the next few centuries Buddhist influence in government grew stronger. The 17th century was dominated by state-imposed Buddhism (with many Shinto elements) as a reaction against an outside threat posed by Christian missionaries.
Japanese civic religion in the 17th century still included elements of Confucianism, while popular religion consisted mainly of Buddhism and Shinto. There was a movement towards a purer Shinto during the next two centuries, culminating in the Meiji Restoration towards the end of the 19th century, when Shinto became the established religion of Japan for a time.
(See the general history article for a more detailed look at Shinto's coexistence with Buddhism.)