A law enforcement officer walks past ICE logo ahead of a press conference on Thursday, May 11, 2017, at the U.S. Immigration and Customs Enforcement headquarters in Washington, DC.

McKinsey & Company, the prominent management consultancy, has stopped working for Immigration and Customs Enforcement after the disclosure last month that the firm had done more than $20 million in consulting work for the agency. The revelation prompted questions from employees at the firm.

McKinsey’s decision was conveyed in a note from the firm’s new managing partner, Kevin Sneader, to former employees. He said the contract, which was not widely known within the company until The New York Times reported it in June, had “rightly raised” concerns.

While stating that McKinsey’s work for the agency did not involve carrying out immigration policies, Mr. Sneader wrote that the firm “will not, under any circumstances, engage in any work, anywhere in the world, that advances or assists policies that are at odds with our values.”

Complaints about the contract come at a time when McKinsey is under fire in South Africa for its role in a vast government corruption scandal that led to the resignation of the country’s former president, Jacob Zuma. The resulting crisis at McKinsey, the most serious in its 92-year history, was the focus of The Times’s article. On Monday, in a speech to a business school in Johannesburg, Mr. Sneader apologized to the nation for McKinsey’s handling of the episode.

Read more from the New York Times:

‘God Bless America’: 100 years of an immigrant’s anthem

Trump’s ace in the hole in trade war: A strong economy

Corruption gutted South Africa’s tax agency. Now the nation is paying the price.

“We came across as arrogant or unaccountable,” he said. “To be brutally honest, we were too distant to understand the growing anger in South Africa.”

McKinsey’s decision to end work with ICE comes amid widespread anger, across the political spectrum, over the Trump administration’s “zero tolerance” policy on illegal immigration that led to the separation of children from their parents — a practice that was ended in June. While Mr. Sneader acknowledged the concerns about McKinsey’s contract, a spokesman said the firm had already finished the job.

However, when asked about the contract before the story was published, McKinsey did not say that the work was ending. What’s more, federal records show that the contract was modified three days after The Times’s story.

The disclosure that McKinsey was working with ICE “caused a lot of discussions and alumni reactions,” one former partner said in an interview. It “caused a bit of drama.”

While several government agencies are involved in carrying out Mr. Trump’s immigration policies, ICE, which oversees detention centers across the country, has come under the most criticism. At least three other consulting companies — Deloitte Consulting, PricewaterhouseCoopers and Booz Allen Hamilton — have also advised ICE, according to federal contracting records.

James Fisher, a spokesman for Booz Allen, said in a statement that the company’s work with ICE involved “information systems, data integration and analytics,” and that it did not involve “the separation of children from adults.” Deloitte declined to comment, and PricewaterhouseCoopers did not respond to a request for comment.

McKinsey’s contract is for “management consulting services” for the agency’s Enforcement and Removal Operations division, though neither McKinsey nor ICE gave details on what that meant.

“Our support, which has ended, has never been focused on developing, advising or implementing immigration policies, including the child-separation policy,” Mr. Sneader said in the note to former employees, whom McKinsey, adopting the practice of universities, calls “alumni.” The note was sent to The Times by a former employee.

McKinsey’s current contract with ICE began during the Obama administration. Most of the work was done after Mr. Trump took office, records show.

McKinsey’s involvement in the South African corruption scandal stemmed from its consulting contract with Eskom, the state-owned electricity provider. McKinsey came under fire because of the size of the payout and because its partner was linked to a business associate of three Indian immigrant brothers who have been accused of using their relationship with Mr. Zuma’s family to siphon money from the state.

McKinsey has paid back the 1 billion rand (about $74.7 million) in fees it took for its work with Eskom. In his speech in Johannesburg on Monday, Mr. Sneader said the contract went against McKinsey’s policy of putting the client’s interests ahead of its own.

“Our commercial approach led to a fee that was too large,” he said. “The fee was weighted towards recovering our investment, rather than being in line with Eskom’s situation. In that context, the fee was too large.”

He added: “This all amounts to an unacceptable breakdown in our governance processes. It should not have happened.”