It seems to be an incredibly common trope for a noble (usually a king or duke) to state their will to their ministers and either pass the title on or declare their heir while they are actively dying. However in history I have hardly heard stories like that, succession usually planned out years if not decades before hand and often the heir taking up an administrative position within the domain like the HRE’s Co-emperors and the like. Are there any historical examples of such late deathbed successions?
Not all successions were set up like that. In my era (Later Han 25-220 CE and Three Kingdoms -280 CE) there were usually three ways the "what happens when the ruler dies." could go. This could include making the eldest son Crown Prince with plenty of time, time at court and administrative experience gained, hopefully making for a smooth succession. Of course, things could go still wrong between the elevation to Crown Prince to the moment they might become Son of Heaven.
There was always the possibility that the Emperor might not have male children. The adult Emperors didn't look around their kinsman and make one an heir as a just in case. It was not unknown for Kings to be a potential problem with Han and claimant successors in the civil war that followed so keeping the imperial family (bar the Emperor's sons) away from court and positions of power was policy till the Jin dynasty. If the Emperor died without a son and heir or in rarer cases, was killed by a controller or forced off the thrown by the Dowager, without a chosen heir then the Empress Dowager had the power to pick from the imperial clan.
If their pick (or the not yet mature son and chosen successor) was later dying before he came of age, they might indeed have a figure on hand at the capital or nearby to ensure a smooth transfer of Emperor. In some cases, a Dowager could overlook the son for another candidate: Dowager Deng overlooked Emperor He's eldest son Liu Sheng on grounds of poor health. Dowager Yan ignored the deposed son and heir Liu Bao though the future Emperor Shun would gain power via a coup. Wu dynasty Dowager Zhu acceded to the young Crown Prince Sun Wan being replaced by the mature Sun Hao at the urging of the chief figures at court though this would not end well for many involved.
So what about deathbed successions? Not unknown. Have a child, don't prepare the ground properly as the child is too young or there is always more time until there isn't. Emperor Ling fell mortally ill in the summer of 189 and had two sons, his eldest Bian who he had doubts about and his second son Xie whom he favoured but the Emperor hadn't prepared the ground. The Empress He was the mother of Bian and her half-brother Jin was popular with the army, they would be major backers of Bian. Emperor Ling's mother Dowager Dong backed Xie but they had less power so, on his deathbed, Emperor Ling entrusted the eunuch commander Jian Shi with the care of his young Xie. So when Emperor Ling died on the 13th of May, Jian Shi tried to install Liu Xie as Emperor but was outmanoeuvred by the He family who installed Bian as Emperor.
In the chaos that soon followed as the lands descended into civil war, some warlords would end up with deathbed (or worse) successions. Tao Qian, the erratic ruler of Xu, died in 194 and told his advisers to choose the rising general Liu Bei over his sons. The ambitious Liu Yan of Yi lost his eldest sons Fan and Dan in 194, they were executed when they attempted to aid their father against the military junta at the Han court, and died that year himself but without choosing an heir. His favoured and youngest son Liu Mao seems to have been incapacitated at that time and key supporters like Zhang Wei chose Liu Zhang for his weak nature though it did provoke internal trouble. The rising warlord Sun Ce was fatally wounded during a hunt by people seeking vengeance in 200 when he was 25 (using Western years for this). His son Shao was possibly not yet born and he chose his younger brother Quan to take over fastening his seal to Quan's belt in front of senior advisers. At 18 years old and part of Sun Ce's councils, Sun Quan was established enough though senior officers and mother Lady Wu did an unofficial regency for the eighteen-year-old.
Yuan Shao 202 had risen to be one of the most powerful figures in the north, though one whose position was under major threat. He had three sons (well possibly four with Mai but the exact relationship is unknown and probably very young), his eldest son Tan was a kind, famed general but his handling of Qing had been poor, Yuan Xi in You of whom little is known, Yuan Shang was handsome and strong and was with his father at Ye. Yuan Shao favoured Shang and took measures for his possible youngest, moving Tan to another line of the Yuan family. However, he still left Tan with an army and lands, and didn't openly declare Shang his heir so was a shock to a lot of people (including Tan) when Shang took over after his father's death. Accusations were that Yuan Shang's allies in Ye like loyal adviser Shen Pei forged the will though it does strongly seem to have been Yuan Shao's intent if never properly prepared as it should have been to ensure a smooth succession. Already Fracotius tensions in the Yuan camp did not ease, it would not be long before the brothers were at war and the Yuan regime would fall to Cao Cao, Shao's former junior alley, by 207.
Cao Cao would secure the succession for himself as King of Wei though only four years before his death after running through several candidates before agreeing to his eldest surviving son Cao Pi. By the end of the year, Cao Pi had got the abdication of Emperor Xian to found the Wei dynasty. He had a son named Rui already but would soon kill Rui's mother Zhen on August 26th 221 (this Rui did not forgive), and Pi seems to have had hopes for another son in Cao Li. So only the day before Cao Pi died on 29th June 226 did he give the quiet son Rui position as Crown Prince. Even then he tried a four-man regency despite Rui being of age.
Cao Rui was handsome and had many many concubines but he doesn't seem to have been particularly active in the harem. His sons died young and the death of Cao Mu He on July 229 seems got him thinking of adoption. Even the birth of Cao Yin (who died before his first birthday) didn't seem to stop plans and in 231, his relatives were ordered to send one son to visit and at some point, he adopted Cao Fang and Cao Xun. However, despite the unusual methods, he did not choose between them and he hadn't replaced his Empress Mao who he had killed on 22nd September 237 so were a few problems to deal with when Cao Rui fell mortally ill in late 238. On 16th January 239, he made the wily Lady Guo Empress, 22nd the seven-year-old Cao Fang was chosen as the heir on the day Rui died.
Between then the choosing of regency was chaotic as Cao Rui dithered and was pressured by his inner circle, going from four to two, to varied people before settling on Cao Shuang and Sima Yi. The latter was returning home from overseeing the destruction of Gongsun Yuan's regime to the far north in Liaodong, he only just got back in time to see Cao Rui on that final day. Alas, the choice of regents would not serve the Wei dynasty or Cao Fang well. The conflict between the regents would see Sima Yi launch a coup against Cao Shuang on 5th February 249, Cao Fang would be deposed on October 17th 251 after trying to plot against Sima Yi's son Sima Shi and lived his life under house arrest. The Dowager Guo maintained skilful resistance against the Sima control but an embarrassing regicide and victories over several revolts later, the Sima's would found the Jin dynasty.
So while I can't speak for the era of your particular interest, deathbed successions are certainly not unknown in other parts of history. Misfortune, people put off the decision of what comes after not knowing death would come as quickly as it did, hopes of another might be a better choice or a child born if there is just more time. Leading to hurried and perhaps not always well-considered or secure succession planning.