KIEV, Ukraine — It was early September, and Ukraine’s new president, Volodymyr Zelensky, faced an agonizing choice: whether to capitulate to President Trump’s demands to publicly announce investigations against his political enemies or to refuse, and lose desperately needed military aid.

Only Mr. Trump could unlock the aid, he had been told by two United States senators, and time was running out. If the money, nearly $400 million, were not unblocked by the end of the fiscal year on Sept. 30, it could be lost in its entirety.

In a flurry of WhatsApp messages and meetings in Ukraine’s capital, Kiev, over several days, senior aides debated the point. Avoiding partisan politics in the United States had always been the first rule of Ukrainian foreign policy, but the military aid was vital to the war against Russian-backed separatist forces in eastern Ukraine, a conflict that has cost 13,000 lives since it began in 2014.

By then, however, Mr. Zelensky’s staffers were already conceding to what seemed to be the inevitable, and making plans for a public announcement about the investigations. It was a fateful decision for a fledgling president elected on an anticorruption platform that included putting an end to politically motivated investigations.