A federal investigation that led President Trump’s longtime lawyer to implicate Trump in two campaign finance crimes this week also secured the cooperation of one of the top-ranking executives at Trump’s private company.

Allen Weisselberg, chief financial officer for the Trump Organization, was granted immunity by federal prosecutors in New York who were investigating Trump’s former attorney Michael Cohen, according to people familiar with the probe.

On Tuesday, Cohen pleaded guilty to eight felonies, including two counts related to hush money paid to women who alleged affairs with Trump. Cohen admitted he violated campaign finance law with the payments, which he said he made at Trump’s direction. The president has denied knowing about the payments when they were made.

Weisselberg, who began working with the Trump family in the 1970s, was one of the executives who helped arrange for Cohen to be reimbursed $420,000 for money paid to keep adult-film star Stormy Daniels quiet, according to a person with knowledge of his role.

The decision to grant Weisselberg immunity gave prosecutors access to one of the highest-ranking figures inside the president’s private company, an executive who is considered practically part of Trump’s family.

Over the decades, Weisselberg rose from serving as an accountant to the keeper of Trump’s personal books. After Trump’s election, he was appointed to help run the trust that controls the president’s assets, along with two of the president’s sons, Donald Trump Jr., a fellow trustee, and Eric Trump, chairman of the trust’s advisory board.

“He was really the guy in charge of the money, and that’s always a position of honor,” said one person close to the Trump Organization who spoke on the condition of anonymity to describe the company’s internal dynamics.

It is unclear whether investigators in New York have sought to get information from Weisselberg beyond his knowledge of Cohen’s reimbursements. Prosecutors also granted immunity to David Pecker, a longtime Trump ally and chief executive of a tabloid publishing company, to describe his company’s role in suppressing stories about the alleged affairs, according to a person with knowledge of the probe.

The Wall Street Journal first reported Weisselberg’s immunity deal.

Weisselberg is the person identified in court filings as “Executive-1,” who prosecutors said helped authorize payments to Cohen, according to one person familiar with his role. He testified last month before a grand jury investigating Cohen.

According to court filings, Cohen in early 2017 submitted an invoice to Weisselberg seeking to be repaid for legal expenses he said he made on Trump’s behalf.

Among the expenses for which he was seeking reimbursement: $130,000 paid to Daniels to keep her quiet about an alleged sexual encounter with Trump.

A person familiar with the Trump Organization said Cohen explained that $130,000 expense, which he had paid to Daniels’s attorney, was a settlement “of a personal nature.”

Weisselberg did not know the nature of the settlement but approved the reimbursement because of Cohen’s long-standing role as counsel to Trump, according to one person familiar with the situation.

In February 2017, Cohen sent Weisselberg an invoice seeking two monthly payments of $35,000 “pursuant to [a] retainer agreement,” according to court documents.

Weisselberg forwarded Cohen’s invoice to another Trump Organization executive, “and it was approved,” prosecutors wrote.

Weisselberg then forwarded that email to another employee, writing: “Please pay from the Trust. Post to legal expenses. Put ‘retainer for the months of January and February 2017’ in the description,” according to court filings.

In fact, prosecutors said, Cohen had no retainer agreement with the Trump Organization at the time, and the invoices were not in connection with any legal services he provided in 2017.

Weisselberg, now 70, got his start in the family business by working as an accountant for Trump’s father, real estate magnate Fred Trump, in the 1970s.

In 2000, he was named chief financial officer of the company. But his role is greater than that: Weisselberg has been at the center of a financial operation that covered all parts of Trump’s life, including his corporation’s finances, his personal accounts and his personal charity.

In a deposition with the New York attorney general’s office, conducted as part of a state investigation into Trump’s charity, Weisselberg recalled being told to fly to Iowa with the foundation’s checkbook in 2016.

Trump was holding a fundraiser for veterans as part of his presidential campaign, and Weisselberg was told that the candidate might want to give out checks that night.

Weisselberg said he was surprised to be asked to accompany Trump. “I had never gone anywhere with Donald on any kind of — anything,” he said, according to a transcript of the interview.

Weisselberg started to describe what he thought of that odd order. But then he stopped himself.

“It doesn’t matter what I thought,” Weisselberg said. “He’s my boss. I went.”

A person close to the Trump family who spoke on the condition of anonymity to describe private discussions said Weisselberg is viewed with the highest respect by the family, calling him “truly a class act.”

Peter Z. Wu, a real estate broker who has worked with the Trump Organization, said Weisselberg was always quietly at Trump’s side during negotiations and handled the payments to the company’s partners.

“He gets involved in all the transactions, all the money flows, so he’s quite an important man, and I’m sure he’s very loyal to Donald,” Wu said. “I would be surprised if they would be able to get too much out of him.”

The low-profile executive was thrust into the headlines last month, when Cohen attorney Lanny Davis released a secret recording Cohen made of a September 2016 conversation with then-candidate Trump.

In the recording, Cohen can be heard discussing the need for Trump to purchase the rights to Playboy centerfold Karen McDougal’s story of an affair with Trump. In their conversation, Cohen told Trump that he had discussed buying the rights to McDougal’s story with Weisselberg.

After the disclosure of the recording, Alan Futerfas, an attorney for the Trump Organization, disputed the idea that Weisselberg had signed off on Cohen’s plan.

“Mr. Weisselberg is a bookkeeper who simply carries out directions from others about monetary payments and transfers,” he said.

But federal prosecutors in New York quickly subpoenaed Weisselberg to appear before a grand jury.

It is not uncommon for prosecutors to offer immunity to a person who may have wittingly or unwittingly facilitated a crime if investigators decide that person is more of a witness than a perpetrator, or if prosecutors decide they cannot get necessary testimony without offering some degree of immunity.

For example, when former Trump campaign chairman Paul Manafort went on trial this month in Alexandria, Va., prosecutors granted immunity to several people who worked on his taxes and finances. One of those witnesses testified that she suspected Manafort was submitting false information to the IRS to lower his tax burden but went along with it.

David A. Fahrenthold and Jonathan O’Connell contributed to this report.