WASHINGTON — Energy Secretary Rick Perry, who has emerged as a central figure in the Trump administration's quickly expanding Ukraine affair, has resigned and will leave his job by the end of the year.

"It's with profound emotion and gratitude that I am announcing my resignation effective later this year as your Energy Secretary," he said in a video to staffers posted Thursday. "There is much work to be done in these upcoming weeks and I remain fully committed to accomplishing the goals that I set out to accomplish at the beginning of my tenure. And then, I will return to my favorite place in the world— Texas— but I'll treasure the memories of what we’ve accomplished together."

President Donald Trump, touring a Louis Vuitton workshop in Texas, told reporters earlier on Thursday that he'd known for six months that Perry was going to leave his post "at the end of the year" and that he already knows who he'll name as his replacement— but did not say who it was.

"Rick has done a fantastic job. But it was time," Trump said.

“Rick and I have been talking for six months. In fact I thought he might go a bit sooner," Trump added. "We have his successor, we’ll announce it pretty soon."

In a resignation letter sent to Trump and made available later Thursday, Perry expressed his gratitude to “Trump and the American people for this opportunity to serve.”

“It has been a tremendous honor to serve our country in your administration in such a meaningful way,” he wrote in the letter, which also said that his resignation would take effect at a date later this year.

A Republican donor who said he spoke to a senior Perry aide had told NBC News earlier Thursday that Perry had told Trump he would be stepping down.

"Secretary Perry notified President Trump in writing today that he plans to resign soon," Canary CEO Dan Eberhart, an oil industry executive, wrote in a text message to NBC.

The departure of Perry, one of the last remaining members of Trump's original Cabinet, comes as his name emerged in the Ukraine affair that has resulted in a Democrat-led House impeachment inquiry into Trump.

The inquiry has centered on a July 25 phone call between Trump and the president of Ukraine during which Trump asked his Ukrainian counterpart to investigate the family of former vice president Joe Biden, Trump's possible 2020 opponent.

The White House has made public a detailed description of the July call, while the House Intelligence Committee made public a lightly redacted version of the intelligence community whistleblower complaint that brought to light the allegations against Trump. The complaint alleged that Trump, in the July phone call, used the power of his office "to solicit interference from a foreign country" in the 2020 election.

Earlier this week, a State Department official who had been interviewed by House Democrats investigating the matter, said that Perry was a member of a trio — who called themselves "the three amigos" — appointed by acting White House chief of staff Mick Mulvaney to spearhead Trump's efforts in Ukraine.

That official, George Kent, a deputy assistant secretary of state, told lawmakers in a closed-door deposition on Tuesday that Perry, U.S. ambassador to the European Union Gordon Sondland and now-former special envoy Kurt Volker were tasked by Mulvaney to oversee Ukraine policy for the U.S. and that other State Department officials were sidelined, while Trump's personal lawyer Rudy Giuliani worked to pressure the Ukrainian government to investigate Hunter Biden, the son of Joe Biden.

Perry has been subpoenaed in the impeachment inquiry.

Late Wednesday, Perry said he'd called Giuliani this spring at Trump's direction to facilitate a meeting between Trump and Ukrainian President Volodymyr Zelenskiy. In comments first reported by The Wall Street Journal, Perry said that Giuliani had brought up allegations of Ukrainian interference in the 2016 U.S. election — which are unfounded — and told him to "be careful" about Zelenskiy.

Giuliani confirmed the call with Perry, telling NBC News: "Everything I said there I probably said on television 50 times."

NBC News reported earlier this month that Trump told House Republicans he was urged by Perry to make the midsummer phone call to Zelenskiy.

Speculation over Perry's resignation had run rampant in recent weeks. Several news outlets reported earlier this month that Perry was expected to announce his resignation by the end of the year. But a Department of Energy spokesperson told NBC News, following those reports, that "while the beltway media has breathlessly reported on rumors of Secretary Perry’s departure for months, he is still the Secretary of Energy and a proud member of President Trump’s cabinet."

Deputy Energy Secretary Dan Brouillette is widely seen as the likely immediate successor to Perry — both because he is the next-ranking official in the department and because it would be difficult for Trump to win confirmation for another pick amid the Ukraine investigation. Brouillette has broad experience in Washington as a former top lobbyist at Ford Motor Company and as the former top aide on the House Energy and Commerce Committee.