The shogun was the military ruler of Japan in the middle ages. There were three distinct episodes: The Kamakura shogunate of the Minamoto clan, reigning from 1192 till 1333, the Ashikaga shogunate which ruled from 1336 till 1573, and the Tokugawa shogunate which ruled from 1603 till 1868 when Imperial authority was reestablishend by Emperor Meiji.
When the Minamoto clan won the Gempei war agains the rival Taira clan, Minamoto no Yoritomo was invested with the title of Shogun and governed Japan from his seat in Kamakura. The Imperial court remained in Kyoto, but had no power. After Yoritomo's death in 1199, the Hojo clan, the family of Yoritomo's wife, seized power and became hereditary Regents for the Minamoto Shoguns, who were as powerless as the Emperors.
In the wake of the Mongol attempts at invasion in 1274 and 1281, resentment against the shogunate grew due to a lack of rewards and the Hojo's monopoly on power. In 1333 Emperor Go-Daigo ordered the vassals to rise against Hojo rule and to reestablish Imperial authority. The Hojo ordered Ashikaga Takauji to crush the rebellion, but the Ashikaga instead joined the rebels. When the tides turned against the Hojo, the last 870 Hojo samurai, including the last three Regents, committed suicide at the Hojo family temple in Kamakura. In 1336, Ashikaga Takauji himself became Shogun. He established his capital at Kyoto.
The Ashikaga shogunate lost power in the Onin war (1467 - 1477), initially a dispute of succession succession to the shogunate. Kyoto was ruined, and fighting spilled over to the provinces, where local warlords (Daimyo) would establish de facto independence from the shogunate and fight amongst each other. While Ashikaga Shoguns would still reside in Kyoto, they became puppets of whoever controlled the capital.
In 1573 the last Ashikaga Shogun was driven from Kyoto by Oda Nobunaga, the most powerful warlord to emerge after a century of near-constant civil war.
After Oda Nobunaga's death, power was seized by his most influential general, Toyotomi Hideyoshi. Hideyoshi had risen through the ranks and was not of noble birth. He attempted to be adopted by the last Shogun who lived in exile, but chose to instead be adopted into the Fujiwara family of court nobility, a family which had held powerful positions at the Imperial court during the Heian Period. Under Oda Nobunaga and Toyotomi Hideyoshi, Japan had been united under one ruler for the first time since the Onin war.
After Hideyoshi's death, Tokugawa Ieyasu, who had been an ally of both Oda Nobunaga and later Toyotomi Hideyoshi, seized power. He defeated a coalition of opposing warlords at the Battle of Sekigahara in 1600. Three years later he was appointed Shogun and established his capital at Edo, modern Tokyo.
The Tokugawa shogunate was the most stable, with various policies implemented to confine the power of the Daimyos. It was an era of peace and prosperity, but also of isolation, with foreign trade strictly controlled and limited to Chinese and Korean traders and a small Dutch trading post. Christianity, which had taken root in western and southern Japan, was forbidden and severely persecuted, and a Christian revolt in Shimabara (western Kyushu) was crushed in 1638, one of the very few instances of serious unrest during Tokugawa rule.
The Tokugawa shogunate came to an end when it failed to control incursions by European powers such as Commodore Matthew Perry's Black Ships. Conservative samurai came to see the shogunate as weak and conspired to restore the Emperor to power. They were successful in 1867 when the 15th Tokugawa Shogun, Tokugawa Yoshinobu, resigned and Emperor Meiji took control of the government.
Shogun is also the title of a book by James Clavell, and a subsequent mini-series.