Heian and Feudal Japan

The first known written reference to Japan was recorded in the Chinese Book of Han in the 1st Century CE. Between the 4th and 9th Century, Japan's many kingdoms and tribes gradually came to be unified under a centralized government, nominally controlled by the Emperor of Japan. This imperial dynasty continues to reign over Japan to this day.

In the year 794, a new imperial capital was established at Heian-kyō (modern Kyoto), marking the beginning of the Heian period, which lasted until 1185. Heian means "peace" in Japanese. The Heian period is considered a golden age of classical Japanese culture. There was great influence from China, including Buddhist religious practices that mixed with native Shinto beliefs. 

Although the Imperial House of Japan had power on the surface, the real power was in the hands of the Fujiwara clan, a powerful aristocratic family who had intermarried with the imperial family. Over the following centuries, the power of the emperor and the imperial court declined, passing first to great clans of civilian aristocrats – most notably the Fujiwara – and then to the military clans and their armies of samurai.

Samurai were the hereditary military nobility and had high prestige and special privileges such as wearing two swords. They cultivated the bushido codes of martial virtues, indifference to pain, and unflinching loyalty, engaging in many local battles.

The Minamoto clan emerged victorious from the Genpei War of 1180–85. After seizing power, they set up his capital in Kamakura and took the title of shōgun. This marked the end of the Heian period and beginning of Japan's feudal era. The feudal era of Japan consisted of three main periods, the Kamakura period, Muromachi period, and Azuchi Momoyama period, each named for the shoguns who controlled Japan. During these periods, the Emperor technically controlled the country, but in reality, the shogun had more political power. 

In 1274 and 1281, the Kamakura shogunate withstood two Mongol invasions (in large part thanks to storms known as the kamikaze winds). In 1333, the shogun was toppled by a rival, ushering in the Muromachi period. During the Muromachi period, regional warlords called daimyō grew in power at the expense of the shōgun. Originally, daimyô reported to the shôgun, but they often had cloer contact and control over the samurai, which helped them grow in power. 

Eventually, Japan descended into a period of civil war. In the late 16th century, Japan was reunified under the leadership of the prominent daimyō Oda Nobunaga. Europeans first arrived in Japan during Nobunaga's rule and brought firearms with them. Nobunaga used them in his war against other samurai to unify Japan in the 1560s. Nobunaga was a brutal ruler, and ruthless towards political opponents. His successor Toyotomi Hideyoshi became the second great unifier of Japan. Hideyoshi launched an invasion of Korea in 1592 to initial success, but eventual a stalemate. 

After Hideyoshi's death in 1598, Tokugawa Ieyasu came to power and was appointed shōgun by the emperor. The Tokugawa shogunate, which governed from Edo (modern Tokyo), presided over a prosperous and peaceful era known as the Edo period (1600–1868). The Tokugawa shogunate imposed a strict class system on Japanese society and cut off almost all contact with the outside world.