The official capital is wherever the Emperor resides. In the 8th Century it was Nara then the Emperor moved the capital ie Imperial residence to Kyoto (western capital) in 794 where it stayed the official capital/imperial residence until 1867.
Meanwhile, power was taken from the nobles and the warriors became the rulers of the land. The chief ruler was the Shogun and the first dynasty was set in Kamakura south of Tokyo. All the government institutions for running the country were set here but Kyoto was still considered the capital because the Emperor lived there.
The Ashikaga Shogunate was set in a district of Kyoto - Muromachi but they were the center of the government not the Imperial Court like it had been. Tokugawa Ieyasu was established in Edo and when he became Shogun in 1603 he based the new shogunate government there.
In the mid-19th century there was a movement to overthrow the shogunate and re-establish the Imperial Court as the center of the government. They were successful but because all the bureaucratic institutions were firmly entrenched in Edo, it was decided that the Emperor would relocate the Imperial Court to Edo. In 1868 Emperor Meiji moved to Edo which was renamed Tokyo
been to both capitals and study Japanese history