KYIV, Ukraine — One of the Ukrainians whose names have surfaced in Rudy Giuliani's ongoing crusade to tar the Bidens is a powerful politician with a knack for playing all sides to his advantage.

Documents and testimony released by Congress as part of President Donald Trump's impeachment investigation have revealed how Ukrainian Internal Affairs Minister Arsen Avakov helped Giuliani associate Lev Parnas gain access to Ukraine's powerful business and political elites as he dug for dirt on the Bidens, exchanging more than 100 messages with Parnas.

But they also show that Avakov warned U.S. Ambassador Marie Yovanovitch and other U.S. Embassy officials about Parnas' activities on behalf of Giuliani and about their efforts to oust her from her job. In fact, Avakov is now overseeing the Ukrainian government's investigation into whether Giuliani associates improperly surveilled Yovanovitch by tracking her phone and computer.

According to testimony from Yovanovitch, on Nov. 15, 2018, Avakov told her that Parnas and Giuliani had reached out to him while he was in the U.S. Avakov said he spoke to Giuliani briefly on the phone, Yovanovitch said, but he told her "he didn't actually want to meet with Mayor Giuliani because of his concerns about what they were doing."

"He thought it was — so he thought it was very dangerous. That Ukraine, since its independence, has had bipartisan support from both Democrats and Republicans all these years, and that to start kind of getting into U.S. politics, into U.S. domestic politics, was a dangerous place for Ukraine to be," Yovanovitch said.

Download the NBC News app for breaking news and politics

In February 2019, Yovanovitch said, Avakov specifically warned her that Giuliani was working with Yuriy Lutsenko, who was then Ukraine's prosecutor general, "to remove me from my post."

Yet within months, Avakov was communicating extensively with Parnas, one of Giuliani's chief operatives in Ukraine. Documents released by the House Judiciary Committee show that Avakov exchanged at least 110 messages with Parnas from April 15 to May 29, 2019, and transcripts indicate that he met with Parnas at least once.

Rudy Giuliani has coffee with Ukrainian American businessman Lev Parnas at Trump International Hotel in Washington on Sept. 20, 2019. Aram Roston / Reuters file

The messages show Parnas trying to set up meetings and share information related to Hunter Biden, the Ukrainian energy firm Burisma, on whose board Biden once sat, and Hillary Clinton. Parnas even asks Avakov for help with security arrangements, and Avakov appears to provide assistance, although it isn't clear whether the assistance is private security guards or public security personnel linked to the Internal Affairs Ministry.

On May 14, Parnas forwarded Giuliani's gratitude to Avakov via WhatsApp. "My dear friend," he wrote. "I would like to thank you for your help and understanding in this difficult situation and for your help personally to me. I reported about this to Respected Rudy, and he today in an exclusive interview with Inter TV Channel [a Ukrainian news channel], expressed to you personally and separately huge gratitude. Waiting for a meeting tomorrow. Thanks!!!!!"

"The way that Avakov, on the one hand, provided security for and communicated with Parnas and at the same time informed Yovanovitch about a smear campaign against her is how he always operates," Tetiana Shevchuk, a lawyer with the Anti-Corruption Action Centre, a nongovernmental Ukrainian activist group known as AntAC, told NBC News. "It's his style. He is everyone's man. He communicates with everybody and preserves ties with all sides."

Oleksandr Lemenov, a Kyiv-based lawyer and activist who focuses on anti-corruption efforts, told NBC News: "Avakov prefers to be behind the scenes. He is a puppet master."

The rise of Arsen Avakov

Avakov, an Armenian born in Baku in Soviet Azerbaijan in 1964, is a wealthy polymath who has shown a skill not just for survival, but also for thriving amid the upheavals of the past 30 years.

As one of Ukraine's richest men, Avakov made a fortune of more than $100 million during several decades leveraging political and business connections from his hometown, Kharkiv, with his role in the banking industry in the 1980s and '90s.

In the immediate aftermath of Ukraine's 2013-14 Euromaidan Revolution, which ousted a pro-Russia government, Avakov was appointed minister of internal affairs. It was meant to be a temporary appointment.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

However, Avakov "began to construct his own system of power from that day," according to Oleksiy Grytsenko, an activist who led part of the opposition movement alongside Avakov during the 2014 revolution.

After being installed as interim minister of internal affairs, "Avakov saved practically all high-ranking law enforcement officials from lustration [the purge of former President Viktor Yanukovych's loyalists after the revolution] and criminal prosecution," Shevchuk said. "In return, they swore loyalty to him."

Avakov didn't simply survive the transition from post-revolutionary government; he thrived in a post from which he controlled the country's powerful internal security agencies, including the National Guard and the National Police.

He has held this role through three presidents and four prime ministers — one of only two Cabinet members asked to continue in their posts from former President Petro Poroshenko's administration into that of President Volodymyr Zelenskiy.

"At first, it looked like he was actually reforming the ministry. But soon, for us, it became clear he was only creating the appearance of reform," Grytsenko told NBC News.

Robert Hyde with President Donald Trump. hydeforcongress.com

Avakov has been a polarizing figure in Ukrainian politics, and numerous controversies have dogged his tenure as internal affairs minister. They include his son's being charged, and then cleared, over corruption related to military procurement; accusations that the Internal Affairs Ministry mishandled investigations into, and allegations that its personnel were involved in, multiple assaults on opposition figures; and that Avakov has cultivated ties with, and protected, far-right organizations such as the National Corps, which the U.S. State Department calls "nationalist hate groups."

But despite frequent calls for Avakov to resign or be fired, he remains ensconced in his post.

According to Grytsenko and other observers, having such a powerful political ally, to whom essentially all armed internal security forces report, has not been especially comfortable for Zelenskiy, who has tried to dilute Avakov's power without challenging him directly.

Zelenskiy "even tried to take control over the National Guard and dismantle it, but the bill was buried in the parliamentary law enforcement committee, controlled by Avakov loyalists," Grytsenko said.

After impeachment

Trump has now been impeached by the House for abuse of power for his efforts in Ukraine and acquitted by the Senate, almost entirely on party lines.

Post-impeachment, Team Trump's efforts have not just continued, but they also have buy-in from some Republican members of Congress, who have signaled their openness to Giuliani's Ukraine research into Joe and Hunter Biden and Burisma.

"The Department of Justice is receiving information coming out of the Ukraine from Rudy," Sen. Lindsey Graham, R-S.C., said on CBS' "Face the Nation" this month.

Graham said Attorney General William Barr "told me that they've created a process that Rudy could give information and they would see if it's verified."

Avakov, meanwhile, finds himself in charge of a Giuliani-related investigation of his own.

In the WhatsApp messages released by congressional investigators, Parnas spoke to GOP activist Robert Hyde about apparent surveillance of Yovanovitch when she was the U.S. ambassador to Ukraine.

Hyde, writing to Parnas, said: "She's talked to three people. Her phone is off. Computer is off. ... She's next to the embassy. ... Not in the embassy ... Private security. Been there since Thursday."

The information was revealed, in subsequent messages, to have originated with a Belgian named Anthony de Caluwe. De Caluwe, in a public statement, said the information he claimed to have was merely an instance of drunken bravado.

Whether or not she was surveilled, it is clear that Trump wanted to oust Yovanovitch — a 34-year veteran of the foreign service. Trump can be heard calling for her to be "got rid of" in an audio recording released by attorneys for Parnas.

The allegations of surveillance triggered shock waves in Ukraine, which acted quickly to quell fears that it was being dragged even deeper into America's Ukraine's controversy. On Jan. 16, Ukraine's Internal Affairs Ministry — the ministry Avakov runs — announced that it was opening a criminal investigation into the alleged surveillance of a foreign diplomat on its territory.

On Jan. 27, the ministry confirmed that personnel from the State Department's Diplomatic Security Service were joining the investigation.

"Creation of this joint group is necessary for the purposes of clarifying the details of this allegation, and to ensure an unbiased investigation of this incident," a spokesperson for the ministry told NBC News in an e-mailed statement.

Part of the statement was attributed to Avakov: "We have a common goal: the protection of human rights, the enforcement of Ukrainian law, and the prevention of violations of the Vienna Convention on Diplomatic Relations."

Shevchuk of AntAC found that if Yovanovitch was surveilled, and was surveilled by a private firm, it was unlikely that any private security firm could have carried out such surveillance inside Ukraine without the knowledge of the government.

"The Ministry of Internal Affairs directly or indirectly controls all private security firms that can do that kind of surveillance. ... You can't open a private security firm without connections in the ministry," Shevchuk said.

A former U.S. law enforcement official who specializes in Ukraine also found it unlikely that any kind of surveillance could have occurred without the ministry's knowledge.

Shevchuk had a simple explanation for Avakov's apparent role playing both sides of the affair:

"He talks to everybody and wants to be useful for everybody."