If President Trump’s goal in withholding U.S. aid to Ukraine was to end the corruption that had plagued successive governments there, last summer was a curious time to do it.

In late May, weeks before Trump ordered nearly $400 million in congressionally approved security assistance frozen, the Defense and State departments certified that the Ukrainian government had taken “substantial actions” toward “decreasing corruption and increasing accountability” and recommended the aid go forward.

New President Volodymyr Zelensky, whose landslide April victory was followed by the election of an absolute parliamentary majority for his Servant of the People party, “had appointed reformist ministers and supported long-stalled anti-corruption legislation,” William B. Taylor Jr., the Trump-appointed senior U.S. diplomat in Ukraine, testified before the House impeachment inquiry late last month.

It wasn’t perfect. There were some worrisome holdovers from the previous government, and Ukrainian oligarchs remained a powerful force.

But “things were moving in the right direction,” Lt. Col. Alexander Vindman, in charge of Ukraine for the National Security Council at the White House, testified when Republicans suggested that Trump was right to hold up the aid.

The impeachment inquiry, which moves this week to public hearings, centers on whether Trump abused the power of his office for personal political gain, and has obstructed efforts to conceal it.

Government witnesses have testified that the security assistance, and a promised Zelensky visit to the White House, were held hostage to a demand for a public pledge by Zelensky that Ukraine would investigate 2020 Democratic presidential challenger Joe Biden and his son Hunter — a paid board member of a Ukrainian gas company accused of corruption during Biden’s vice presidency. Trump also wanted the authorities in Kyiv to investigate what was alleged to be Ukrainian involvement in Democratic efforts to undermine his 2016 campaign, a conspiracy theory for which no evidence has surfaced.

The president, in his defense, asserts that he was concerned about corruption writ large in Ukraine, not in securing some 2020 election advantage. In addition, he says he was angered that European allies were not doing enough financially to help the beleaguered country, leaving the United States to carry the can.

“Corruption is incredible in Ukraine, which bothered me a lot,” Trump told reporters early this month. “And it also bothered me very, very much that Germany, France and all of these other countries aren’t putting up money, but we’re always the sucker that does it.”

Neither claim holds up under close scrutiny.

When Zelensky expressed appreciation, in a July 25 telephone call with Trump, for years of U.S. security aid, Trump responded by asking for “a favor.” He pressed Zelensky to look into Biden and the Democrats, advising him to contact the president’s personal lawyer Rudolph W. Giuliani and Attorney General William P. Barr for details.

Trump did not mention any wider concern about overall corruption related to U.S. assistance, the subject that he and senior administration officials now insist was the basis for the sudden holdup after years of steady security aid.

European nations have far outpaced the United States in Ukraine, spending $18.3 billion since Russia annexed Crimea in 2014 and launched an ongoing separatist war in the eastern part of the country that has left at least 13,000 people dead. The bulk of the money — $16.8 billion — came from the European Union and regional international development banks, including the European Investment Bank and the European Bank for Reconstruction and Development, to which the United States is also a major donor. The rest, $1.5 billion, came bilaterally from the 28 E.U. countries.

Aid has paid for everything from tents and food for refugees to helping train firefighters and paramedics, to more esoteric projects such as identifying and protecting old-growth forests in western Ukraine’s Carpathian mountains.

The biggest individual European donors were Germany, Sweden, Poland and France, according to E.U. figures. Outside Europe, Canada has also been a major channel of aid and military training and assistance and has led Operation Unifier, an international effort to train troops in western Ukraine.

By contrast, combined military and nonmilitary assistance from the United States has totaled about $4 billion over the same period, in addition to humanitarian relief and several tranches of billion-dollar loan guarantees for budget stabilization.

Economic and anti-corruption progress in Ukraine would “not be possible without strong bipartisan support from the United States, and very, very strong support from the European Union,” Ukrainian Finance Minister Oksana Markarova said at a panel discussion with several officials from the new government held last month at the Carnegie Endowment for International Peace in Washington.

Another official at the event, Katarina Mathernova, who works on Eastern European and international financial institution issues at the European Commission, said flatly that “the European Union is the largest partner and donor to Ukraine.”

Even as it favorably, and inaccurately, compares U.S. assistance to that of Europe, the administration has also congratulated itself on its support for Ukraine in comparison to that of former president Barack Obama. Total figures of annual foreign and military aid, however, have been similar through the two administrations, although Trump decided in late 2017 to allow “lethal” defensive weaponry. While Obama-era aid included many of the nonlethal defense items also on the current assistance list, Obama had rejected appeals from within his own administration to include lethal defense items, on the grounds that it would escalate the conflict with Russia.

Then-Ukrainian President Petro Poroshenko had pressed for delivery of sophisticated Javelin antitank weapons since 2015. A bipartisan majority in Congress was critical of Obama’s hesitation and in 2016 passed legislation backing such weaponry, but Obama was unmoved.

In 2017, senior Trump national security officials agreed that a package of lethal aid to help Ukraine defend itself against Russian aggression​, including a $47 million grant to finance the purchase of 210 Javelin missiles, would be a smart move. But they had trouble persuading the president, who, like Obama, was reluctant to cross Russian President Vladimir Putin and who also had a “reticence to provide anything for free,” one former U.S. official recalled.

Then-national security adviser H.R. McMaster had a Power Point presentation drawn up explaining how the Javelins were defensive weapons and would be highly effective against a superior Russian military, the official said. Although Trump approved the shift to lethal aid in December of that year, agreement on the Javelins was delayed for a week.

Money for the Javelins, as is normal in such transactions, was paid directly to Raytheon, the system manufacturer, by the United States. Although Ukrainian troops were trained to operate them, the Javelins have not been deployed. They are in a warehouse about 1,000 miles from the front lines, as a symbol of U.S. support.

Trump first raised a conspiracy theory about Ukrainian interference in the 2016 presidential election just three months after taking office. He periodically returned to the subject, suggesting — despite the opposite conclusions of the U.S. intelligence community — that it was Ukraine, not Russia, that had interfered, and that it was to benefit Hillary Clinton, not him.

This year, Congress approved nearly $400 million in combined Defense and State security funding to Ukraine, similar to what was authorized last year and part of the uninterrupted flow of aid that had continued through two administrations since 2014.

The aid package, drawn up by the two departments, included sniper rifles, rocket-propelled grenade launchers and counter-artillery radars, electronic warfare detection and secure communications facilities, and training support. Although Ukraine had asked for an additional shipment of Javelins, they were to be paid for with Ukraine’s own funds rather than U.S. assistance.

But when the official U.S. delegation to Zelensky’s May 21 inauguration returned to Washington with high hopes for the new government and U.S.-Ukraine relations, they found Trump in a foul mood. The president started the May 23 meeting “with kind of a negative assessment of the Ukraine . . . it’s a terrible place, all corrupt, terrible people,” Kurt Volker, the administration’s special envoy to Ukraine, testified before the impeachment inquiry.

According to official testimony and reports from Ukraine, the White House began to press for a public statement by Zelensky pledging to investigate the Bidens and the Democrats. That pressure was transmitted to the new government by Taylor, Volker and Gordon Sondland, the U.S. ambassador to the European Union, who recently amended his impeachment testimony to agree that the conditions for getting aid and a White House visit were clear.

In mid-July, as a Sept. 30 deadline for approving the fiscal year’s security assistance to Ukraine was approaching, those working on the issue for the White House were told without explanation that it was being held up on Trump’s orders by the Office of Management and Budget.

After meetings at increasingly high levels through mid-August — at which there was “unanimous” agreement of all agencies that the aid should go forward — Vindman testified that he was asked to draft a “Presidential Decision memo” for Defense Secretary Mark T. Esper, Secretary of State Mike Pompeo and John Bolton, the president’s national security adviser, reflecting their “consensus” views to release the funding, to present “to the president for a decision.”

Their meeting with Trump took place on Aug. 16. Vindman testified that he was given conflicting reports of its outcome, saying that the issue wasn’t raised, or that it was raised but the president “didn’t act on the recommendation.”

It was not until late August that a story in Politico publicly revealed the aid freeze, sparking strong bipartisan pushback by lawmakers.

In quick succession in early September, a whistleblower complaint raising concerns about the Trump-Zelensky call was making its way through the government. Bolton left his White House job. The Senate prepared a bipartisan resolution rebuking Trump for withholding the aid. The Sept. 30 end of the fiscal year approached, and with it, the possibility that authorization for the aid would expire.

On Sept. 11, the administration notified Congress that the security assistance hold had been lifted.

Michael Birnbaum in Brussels and David L. Stern in Kyiv contributed to this report.

This story has been updated to note that the United States is a major donor to the European Bank for Reconstruction and Development.