A new capital city named Heian was built in A.D. 794. It would be later known as Kyoto. It was Japan's capital for more than 1,000 years. During the A.D. 800s, the emperor was losing power and the government weakened. Most of the emperors were only children and regents had to govern them. Soon, the regents refused to give up power and took over. They came from a clan called Fujiwara. The regents just sent the emperors away to study. Soon nobles wanted to take over. The Fujiwara gave lands to them to govern in return of not paying taxes. The nobles formed private armies of warriors called the samurai. The samurai honored the code of Bushido. They fought on horseback with swords, daggers, and bows and arrows. They fought for honor and would rather die in battle than betray their lord.
In 1180, the Gempei war was fought between the two most powerful clans: the Taira family and the Minamoto family. When the leader Minamoto Yoritomo won the war, the emperor gave him the title of Shogun, so that he may not betray him. Shogun was commander of all the emperor's military forces. The emperor was head of the country, but had no power. Meanwhile, the shogun had control over everything. Two separate governments were created. The shogun set up his government at his headquarters in Kamakura. Japan's government was run by series of shoguns for the next 700 years. When Mongols attacked in the late 1200s, the Kamakura shogunate fought back. When the Mongols crossed the sea, typhoons smashed the ships. Japan was safe and named the typhoons kamikaze meaning "divine wind". The Kamakura shogunate lasted until 1333. They felt poor when land owned by samurai became smaller and smaller. The emperor rebelled with many samurai. At the end, the emperor refused to give more land to the samurai. A general named Ashikaga Takauji became shogun and formed the Ashikaga shogunate. They divided the country into smaller lands. Daimyo headed the small areas.
They pledged loyalty to the emperor and the shogun. However, they ruled their lands like independent kingdoms. They formed private armies made up of samurai warriors. The samurai became vassals of a daimyo. They gave oath to the daimyo that they will serve him in times of war. In return, they were given land from daimyo. They gave more land than the shogun had given them. The bond between a vassal and a lord is feudalism. More wars came like the Onin War that almost completely destroyed Kyoto. Weak shoguns came after, but powerful daimyo resisted them. That's when the Ashikaga shogunate ended in 1567. The daimyo too over Japan.