The first human inhabitants of the Japanese archipelago have been traced to the Paleolithic, around 38-40,000 years ago. The Jōmon period, named after its cord-marked pottery, was followed by the Yayoi period in the first millennium BC when new inventions were introduced from Asia. During this period, the first known written reference to Japan was recorded in the Chinese Book of Han in the first century AD.
Around the 3rd century BC, the Yayoi people from the continent immigrated to the Japanese archipelago and introduced iron technology and agricultural civilization.
Because they had an agricultural civilization, the population of the Yayoi began to grow rapidly and ultimately overwhelmed the Jōmon people, natives of the Japanese archipelago who were hunter-gatherers.
Between the fourth and ninth centuries, Japan's many kingdoms and tribes gradually came to be unified under a centralized government, nominally controlled by the Emperor of Japan. The imperial dynasty established at this time continues to this day, albeit in an almost entirely ceremonial role. In 794, a new imperial capital was established at Heian-kyō (modern Kyoto), marking the beginning of the Heian period, which lasted until 1185. The Heian period is considered a golden age of classical Japanese culture. Japanese religious life from this time and onwards was a mix of native Shinto practices and Buddhism.
Over the following centuries, the power of the imperial house decreased, passing first to great clans of civilian aristocrats – most notably the Fujiwara – and then to the military clans and their armies of samurai. The Minamoto clan under Minamoto no Yoritomo emerged victorious from the Genpei War of 1180–85, defeating their rival military clan, the Taira. After seizing power, Yoritomo set up his capital in Kamakura and took the title of shōgun. In 1274 and 1281, the Kamakura shogunate withstood two Mongol invasions, but in 1333 it was toppled by a rival claimant to the shogunate, ushering in the Muromachi period.