WASHINGTON — Two days after a whistleblower secretly filed a complaint about President Donald Trump's dealings with Ukraine in August, two top congressional staffers arrived in Kyiv on a routine business trip that ended up setting off alarm bells on Capitol Hill.

The aides work for the Democratic leadership of the House Appropriations Committee, which is responsible for federal spending. They had been dispatched to make an on-the-ground assessment of the cash Congress has been pumping into former Soviet states — including Moldova, Georgia and Ukraine — to aid their defenses against Russian aggression.

But after traveling from Chisinau, Moldova, for two days of meetings and Ukrainian special-forces training observation in Kyiv and Berdychiv starting on Aug. 14, the staffers were shocked to learn from U.S. embassy officials that there was no new money coming into Ukraine, a congressional aide familiar with their trip told NBC News. The Trump administration had frozen military aid to the country in the midst of its war with Russia.

What's more, the two Appropriations staffers, Becky Leggieri and Hayden Milberg, couldn't even get an explanation for the holdup, because embassy officials didn't know the reason, the aide said. That set off a scramble in Washington to find out what happened to the hundreds of millions of taxpayer dollars that had been specifically earmarked by Congress for Ukraine and that now play a pivotal role in a mushrooming scandal that threatens to lead to the president's impeachment.

The anonymous whistleblower, a CIA employee, has received a great deal of attention for exposing what Democrats say was Trump’s plot to pressure Ukraine into investigating a rival for re-election — former vice president Joe Biden — to help him politically in exchange for receiving military aid. But even if the whistleblower had not stepped forward, there's a chance that the scheme would eventually have been exposed by a combination of congressional accountants like Leggieri and Milberg, whose job it is to keep track of every major expenditure, and various executive branch officials who have emerged to share the pieces of the story they knew.

The appropriations staffers didn't know about the Biden angle, only that military aid was being held up. The whistleblower sewed it all together — and did that in time to prevent a deal from being consummated or for the freeze on the funds to become permanent. But when the staffers realized the money was not flowing, they set off important alarm bells.

"As soon as Appropriations Committee staff learned that Ukraine Security Assistance Initiative funding had been held up, the committee began making urgent inquiries of the Defense Department to understand the situation," House Appropriations Committee Chair Nita Lowey, D-N.Y., said in a statement to NBC News. "After the Defense Department told our staff that the hold originated at the Office of Management and Budget, we began pressing them for an explanation."

They wouldn't get one, receiving only a vague acknowledgment that a re-assessment of U.S. interests was being done, and that only after the freeze became public two weeks later. But pressure from the lawmakers who hold the purse strings for the government is not insignificant.

At the time of the staffers' visit, the highest ranking U.S. diplomat in Ukraine, Bill Taylor, was "beginning to fear that the longstanding U.S. policy of strong support for Ukraine was shifting," he told House impeachment investigators in a closed-door deposition in late October. Even two weeks later, when he sent a cable to Secretary of State Mike Pompeo to inquire about whether there had been such a reversal in U.S. policy, Taylor testified, it still had not occurred to him that the aid could be conditioned on Ukraine opening an investigation touching on American politics.

"That, however, would change," he testified.

Ultimately, the visit by Appropriations staffers played only a modest role in exposing Trump's actions on Ukraine, which was thrust further into public view last week with the first open televised hearings, including one featuring Taylor. But that piece of the puzzle — first discovered by NBC News in a routine House travel disclosure filing made on Nov. 8 — sheds light on how Trump's actions were partially revealed by wonky number-crunchers, who typically toil away far from the spotlight.

As legendary Chicago mobster Al Capone found out when he was put away for tax evasion, accountants are quick to catch on when something is amiss. All across Washington this summer, in the sleepy offices of the federal government infrastructure, red flags were raised. The same thing was happening at the U.S. embassy in Kyiv. In some cases, the hands being raised belonged to officials within the Trump administration who worried that the suspension of aid was illegal.

The hunt to find out why the money wasn't moving played out on Capitol Hill and across several federal agencies at the same time the whistleblower complaint was quietly winding its way through separate government channels in August and early September, and it illustrates the difficulty anyone connected to the administration would have in hiding a purported plot to withhold federal funds.

It also raises the possibility that the episode would have been discovered without the whistleblower. There are just too many nonpartisan civil servants who come in contact with a $391 million spending package to execute such a maneuver undetected, according to experts on the federal budget process.

"You could try to create a quid pro quo by holding up the money and hope you get your quo before anybody finds out, but it wouldn't take very many weeks," said Kate Eltrich, a former Senate appropriations aide and Obama administration OMB official. "If you were trying to do something nefarious, it would be very difficult to contain that to a small number of people."

In the case of the Ukraine money, which included defense dollars and State Department grants for the purchase of weapons that Congress required the administration to spend, the sprawling network of federal officials tasked with overseeing aspects of the spending included House and Senate members of both parties, their staffs, nonpartisan budget officials at the State and Defense departments and career government workers at White House agencies.

The top U.S. diplomat in Ukraine, William Taylor, and career Foreign Service officer George Kent, behind, testify before the House Intelligence Committee on Nov. 13, 2019. J. Scott Applewhite / AP

The pause in funding spilled into public view on Aug. 28, two weeks after the congressional aides arrived in Kyiv, when Politico published an article in which an unnamed senior administration official said the spending was frozen pending a review of whether its release was deemed in the best interests of the United States. The article, which did not mention any effort to secure an investigation into the Joe Biden or his son Hunter, quoted Democratic lawmakers charging that Trump was helping Russian President Vladimir Putin at the expense of Ukraine.

It wasn't until after that article was published that OMB finally responded to House appropriators with a similarly vague explanation for why the money was being withheld.

Ultimately, it would take only a matter of weeks for scattered data points to reveal more edges of the puzzle. On Sept. 9, the director of national intelligence notified House Intelligence Committee Chairman Adam Schiff, D-Calif., that a whistleblower had raised a matter of "urgent concern" that the DNI overruled. The whistleblower already had consulted with a member of Schiff's staff before filing the complaint in August, according to The New York Times, and Schiff was aware of at least the outlines of the concern.

The Intelligence Committee "was unaware of the freeze in security assistance at the time the (appropriations) staffers traveled to Kyiv and had no interaction with them prior to their trip," an Intelligence Committee official said in an email to NBC News. "At no point has the Committee discussed whistleblower matters with them, either."

On the same day that he was told of the "urgent concern" matter, Schiff and the chairmen of two other committees sent White House counsel Pat Cipollone a letter demanding that the administration preserve and transmit records related to the possible withholding of aid to Ukraine as a means of forcing that country to open investigations into Joe Biden — a leading contender to challenge Trump in 2020 — and the 2016 U.S. presidential election.

Two days later, after the White House counsel's office received the whistleblower complaint from the Justice Department, Trump released the money for Ukraine. That decision was announced publicly by Senate Appropriations Committee Chairman Richard Shelby, R-Ala., as he tried to fend off amendments to a military spending bill, assuring his colleagues they didn't need to force the White House to lift the hold because Trump had assured him it already had been done.

In the weeks since the whistleblower's complaint was made public in late September, along with a White House summary of a July 25 Trump call with Zelenskiy in which the leaders discussed both U.S. support for Ukraine's defense and the Bidens, a parade of current and former U.S. officials have testified that Trump and a rump group of his hand-picked political emissaries conducted a shadow foreign policy with Ukraine that focused on boxing Zelenskiy into a simple trade.

If Zelenskiy wanted the money, he had to publicly announce the opening of investigations that would cast aspersions both on Biden and on the U.S. intelligence community's finding that Russia interfered in the 2016 election to help Trump win the White House, the officials have said under oath. The latter would require Ukraine's president to fictitiously implicate his own nation and exonerate its mortal enemy in service of Trump.

While Trump and his allies argue there's "no harm, no foul" because Ukraine ultimately got its aid, the behind-the-scenes machinations in Congress reveal just how tenuous the situation became, with the flow of aid not resuming until after lawmakers began asking questions.

The crisis wasn't fully averted, because there wasn't enough time left to spend all of the funds before the fiscal year ended on Sept. 30, as government budget officials ultimately told Congress.

Laura Cooper, an assistant secretary of Defense, testified that the government managed to get roughly 80 percent of the dollars to Ukraine by the end of September. To ensure the remainder didn't disappear, new language had to be tucked in to a must-pass spending bill known as a continuing resolution to claw back the unspent funds and then reissue them, giving the administration another year to spend the money.

Even now, as Trump faces potential impeachment in the House, it's not clear that all of the funds have yet made it to Ukraine.

"Thanks obviously to the Congress we got the language in the continuing resolution that thankfully will enable us to obligate all of the funding, ultimately," Cooper told the House in her closed-door deposition.

And both in Congress and within the administration, the freeze triggered concerns that aid suspension was not just politically questionable but also illegal, according to interviews with congressional aides as well as transcripts from witness depositions in the impeachment proceedings.

"An important part of the accountability of our system is that there are people whose sole job is to carry out what is required by the law or policy," Eltrich said, adding that having those civil servants is crucial if "you want to prevent corruption."

Cooper, in her deposition, explained that the administration can only refuse to spend money appropriated by Congress if it takes one of two steps: a "presidential-level rescission," in which the president formally cancels the money and notifies Congress, or a "reprogramming action," in which the Pentagon in this case would assign the money to another priority.

Neither of those steps took place, Cooper testified. Mick Mulvaney, the president's acting chief of staff, acknowledged the White House had been aware of the legal issue regarding not spending the funds set aside by Congress during his news conference last month.

"We knew that that money either had to go out the door by the end of September," Mulvaney said, "or we had to have a really, really good reason not to do it."

So did two House appropriations aides who spent part of their summer at the U.S. embassy in Kyiv.