This is a very difficult question to answer, as while there are many pieces of research on the history of the Chinese language, there is no clear indication of which language was the official language (官話) of each of the 27-30 dynasties.
However, the official language ought to be tied to the origin, where the force to create a new dynasty was originated. However, this couldn't be practically correct, because each of the dynasties may not have lived long enough to change the official language drastically to its likes - the freshest example is the Ching Dynasty (qing/ching), while it was created by 滿人, that originated in Northeast China (關外) who spoke 滿州話 and used 滿文, but after 200 years of governing, it still was not been able to alter the official language that was used in Ming Dynasty but minor changes (actually it has adopted the Chinese language instead).
So, what else provides clues to the official language at different eras? One is to look at the Capital City of each dynasty. After 5000 plus years and 30 plus dynasties, the capital city has always been located among a handful of cities - 咸陽,西安,長安,洛陽,北京,南京, so one of the prevalent, and earliest, dialects, in the region that covers those cities must have the most influence, which includes - Gan(贛?), Hakka(客/汉語), Wu(吳語), and most importantly - Central Plane Mandarine (中原普通話).
Central Plane Mandarine (中原普通話) is a dialect of Mandarin Chinese spoken in the central and southern parts of Shaanxi, Henan, southwestern part of Shanxi, the southern part of Gansu, the far southern part of Hebei, northern Anhui, northern parts of Jiangsu, southern Xinjiang and southern Shandong. Note that all the ancient capital cities are located in this region, which was home to the Chinese majority - Han(漢族).
However, it is worthy to note that there are at least 15 subdialects under the umbrella of the dialect (Central Plane Mandarin). A list of the subdialects is provided in here.
ADD: When also named "Mandarin", it differs from the Modern Mandarin, as the latter has become the mainstream language not until the 19th century, and is closely related to 北京話, which was much less dominant prior to Ming and Qian/Ching Dynasties.
Approximate location of Central PLane China (中原)