Ambassador William B. Taylor Jr. looked out over the front lines of Ukraine’s long war with Russian-backed separatists last July, taking in a damaged bridge and then, farther in the distance, an “armed and hostile” enemy.

Taylor had taken the job of acting U.S. ambassador to Ukraine reluctantly, he said in congressional testimony Tuesday. His decision came only after assurances from Secretary of State Mike Pompeo in late May that President Trump was committed to helping Kyiv hold off forces, armed and funded by Moscow, that had besieged the country for nearly five years.

Now it was July and Taylor was already doubting both his decision and his country’s intentions.

The Trump administration’s official policy, which had bipartisan backing, was to support a young democracy “struggling to break free of its past” and battling Russian aggression. But it was becoming increasingly clear to Taylor that those noble intentions were being “fundamentally undermined by an irregular, informal channel of U.S. policy-making” in which Trump and a handful of allies were withholding des­perately needed military aid in exchange for political favors that would benefit Trump’s reelection campaign.

The worrisome signs had been building for weeks. Taylor’s predecessor had been recalled from Kyiv under questionable circumstances. A few days before his visit to the front lines, Taylor had received a report from Washington that the $391 million in military aid was being held up until Ukraine’s new president committed to investigations that would help Trump.

Perhaps most troubling, the ambassador couldn’t get a readout of a call that had taken place one day earlier on July 25 between Trump and Ukrainian President Volodymyr Zelensky. That conversation would trigger an extraordinary whistleblower complaint as well as a House impeachment inquiry that would threaten Trump’s presidency.

Eventually, Taylor would be called back to Washington for day-long testimony before Congress in which he described his distress in an excoriating, 15-page opening statement.

But, on this day, standing on the front lines with a Ukrainian commander, Taylor was most worried about the betrayal of a desperate ally at the hands of an American president.

The 72-year-old ambassador gazed out at the guns and troops on the other side of the bridge. “Over 13,000 Ukrainians had been killed in the war,” he recalled thinking. “More Ukrainians would undoubtedly die without U.S. assistance.”

Taylor’s 50 years of service spanned some of America’s greatest successes as well as some of its most catastrophic blunders. He had graduated from the U.S. Military Academy and fought with the 101st Airborne Division in Vietnam as an infantry officer. After the Sept. 11, 2001, terrorist attacks, he had done stints in Iraq and Afghanistan, during some of those wars’ darkest days, overseeing reconstruction aid.

In 2006, President George W. Bush tapped Taylor to serve as ambassador to Ukraine, a place he described as “special” to him and critical to the security of the United States and its European allies.

Taylor was retired from the State Department and working at the nonpartisan U.S. Institute for Peace when Pompeo asked him to rush to Ukraine to take the place of the recently departed ambassador, Marie Yovanovitch, who Taylor said he thought had been “treated poorly, caught up in a web of political machinations both in Kyiv and Washington.”

Taylor, who feared that the problems that spurred Yovanovitch’s ouster were still present, sought out the advice of friends and colleagues. One former mentor told him, “If your country asks you to do something, you do it — if you can be effective.”

His wife, he recalled in testimony, urged him in “no uncertain terms” to turn down the appointment. Taylor also sought out the advice of Kurt Volker, who recently stepped down as the U.S. special representative for Ukraine amid the growing controversy over his role in withholding American aid.

“I’m still trying to navigate this new world,” Volker texted him this spring.

“I’m not sure that’s a world I want to set foot in,” Taylor replied.

What followed, according to Taylor’s testimony, was the agonized awakening of a diplomat who arrived certain that he was being put in place to deliver implacable American support, but gradually came to understand that the entire U.S. relationship was being subverted for the president’s political gain.

Taylor came to Kyiv so confident in his mandate that he brought hard copies of two documents: a congratulatory letter from Trump to Ukraine’s newly elected leader, in which Trump invited Zelensky to a meeting at the Oval Office, and a framed pledge by Pompeo that the United States would never recognize Russia’s annexation of Crimea.

Within days, however, Taylor began to detect signs of an “irregular, informal” diplomatic channel competing with his own, and a secret agenda seeping into U.S. policy. Upon arrival, he wrote, he faced “a weird combination of encouraging, confusing, and ultimately alarming circumstances.”

Among the first clues was the resistance he encountered trying to deliver on Trump’s White House invite. Before he could even begin to discuss dates, Taylor said, two other diplomats informed him that Trump first “wanted to hear from Zelensky,” though it was not clear yet about what.

On June 27, Taylor got a fuller explanation from Gordon Sondland, a wealthy Trump donor who had been named U.S. ambassador to the European Union. In a phone call, Sondland told Taylor that the president wanted assurances that Zelensky would not stand in the way of “investigations.”

What that meant was left unsaid. But by then, there were other indications of Trump’s intent. Among them were odd statements by his lawyer, Rudolph W. Giuliani, that he was pursuing meetings with officials in Ukraine that he hoped would deliver politically valuable material to his client.

There were also disconcerting signs that those responsible for the “irregular channel” were seeking to hide their tracks. On June 28, Taylor was scheduled to join Sondland and others on a conference call with Zelensky. But before the call got underway, Sondland said that “he wanted to make sure no one was transcribing or monitoring as they added President Zelensky to the call.”

“I sensed something odd” about that request, Taylor wrote in his testimony.

Volker, an old friend of Taylor’s, also seemed to be pursuing aims at odds with the Trump administration’s official policy. In that same call — before Zelensky joined it — Volker said he would be meeting with the Ukrainian leader days later and planned to press him to commit to investigations that would “get to the bottom of things.”

Taylor was so troubled by the dissonant signals that he reported the conversation to Deputy Assistant Secretary of State George Kent, putting his concerns in a memo that presumably now resides among the files at the State Department that Pompeo has not yet furnished to impeachment investigators.

In mid-July, Taylor began to assemble a fuller picture of the Ukraine intrigue.

On a video conference call with White House officials on July 18, Taylor heard the voice of someone out of the camera’s frame, an official from the Office of Management and Budget informing the group that she had been instructed not to allow any additional military aid to flow to Ukraine until further notice.

“I and others sat in astonishment,” Taylor said. “The Ukrainians were fighting the Russians and counted on not only the training and weapons, but also the assurance of U.S. support.” The OMB official offered no explanation for the sudden suspension of this aid, except to say that “the directive had come from the president to the chief of staff to OMB.”

“In an instant, I realized that one of the key pillars of our strong support for Ukraine was threatened,” Taylor testified. “The irregular policy channel was running contrary to the goals of longstanding U.S. policy.”

The cessation of aid appears to have caught the attention of Cabinet-level officials in ways that other developments — including the removal of the U.S. ambassador to Ukraine in May, and Giuliani’s public comments about Kyiv conspiracy theories — had not. The Pentagon swiftly produced an analysis showing that the military aid was effective and should continue. Pompeo, CIA Director Gina Haspel and national security adviser John Bolton sought a meeting with Trump to raise the issue, but delays and difficulties prevented that from happening until September.

Meanwhile, Taylor’s isolation in Kyiv prevented him from learning in real time about disturbing developments at the White House. It wasn’t until July 19 — in a call with Fiona Hill, the White House’s top adviser on Russia — that Taylor learned about a meeting nine days earlier in Washington at which Sondland told members of a Ukraine delegation that their existing anti-corruption work wasn’t enough. They needed to look back at cases regarded as closed, Sondland said.

Bolton and others saw Sondland’s line as a clear reference to Trump’s desire to have Ukrainian authorities dig up dirt on former vice president Joe Biden and his son Hunter, who had secured a lucrative position on the board of a Ukrainian gas company at a time when his father was overseeing Obama administration policy.

Trump was also determined that Zelensky pursue discredited conspiracy theories involving Democratic computer servers supposedly being hidden in Ukraine. Bolton halted the meeting on the spot, according to Taylor’s testimony, telling Hill to go “brief the lawyers” on what had happened and likening the proposed transaction to a “drug deal.”

In Kyiv, it fell to Taylor to decipher these puzzling developments for increasingly worried Ukrainian officials. Often, he had only partial answers, in part because officials in his own government were working to keep him in the dark. When he heard that Volker had met with Giuliani about Ukraine, Taylor tried to confront Volker, asking him if it were true, but “received no response.”

At other moments, Sondland and Volker laid out aspects of their scheme with surprising candor. On July 19 and 20, the two diplomats engaged Taylor in a series of encrypted texts and phone calls, saying that prospects of a Trump-Zelensky call were improving but that Zelensky had to convince Trump that he would “leave no stone unturned” regarding Trump’s sought-after probes.

Trump used his July 25 call with Zelensky to secure that very commitment, reminding the leader of Ukraine how much aid his country received from the United States before soliciting dirt on Biden and material that might help substantiate 2016 conspiracy claims with the line: “I would like you to do us a favor though.”

Again, the details were hidden from the country’s acting ambassador. “Strangely,” Taylor testified, “I received no readout of the call from the White House,” even though he was scheduled to meet with Zelensky the next day.

As the shadow policy in Washington became clearer to him, Taylor sought to raise alarms. In late August he met privately with Bolton in Kyiv and said he expressed “serious concern” about the conditions Trump was putting on military aid.

At Bolton’s urging, Taylor wrote a cable to Pompeo. It went unanswered.

Nearly a month later, Taylor was in Washington, laying out his story for Congress.

CORRECTION: A previous version of this story misstated who accompanied Ambassador William B. Taylor Jr. on the front lines in eastern Ukraine. It was a Ukrainian military commander, not the president.