In Japan, it is not always the oldest son who inherits his father's position. Most of the time, important posts like daimyo, and especially Shogun, are taken over by the eldest son, but sometimes a younger son is chosen instead. If the Shogun does not have any sons at all, there can be even more confusion in choosing a successor when he dies.
After a Shogun or daimyo dies, his leading subordinates meet together and decide who will be the heir. Usually the person indicates who he wants to take over once he dies, but until the meeting when a new Shogun or daimyo is selected, this is not guaranteed. The only way to make sure your chosen heir is selected to replace you is to retire while you are still alive, and appoint your own successor. When the seventh Shogun, Ietsugu died, he did not have any sons. All of his daimyo met and discussed who to appoint as the new Shogun. There are three main families of relatives to the shogun. These are the Mito family, the Kii family and the Owari family. These close relatives of the Shogun are called the Tokugawa Sanke (three Tokugawa families).
In the end, the head of the Kii family was chosen, and he became the eighth Shogun, Yoshimune.