Mr. Trump told the two aides to work it out on their own. A person close to Mr. Cipollone denied that there was concern about bringing aboard another outside lawyer.

Before Mr. Gowdy could be added, however, Mr. Trump needed to meet with him. So the two sat down for lunch at the White House on Tuesday; Jared Kushner, Mr. Trump’s son-in-law and senior adviser, joined them for part of the meal.

It went pleasantly enough, people briefed on what took place said, despite Mr. Trump’s skepticism of Mr. Gowdy, who has often tried to distance himself from the president. But by late in the day, Mr. Trump signed off on hiring Mr. Gowdy. Still, there were procedural issues to be dealt with before he could formally be announced, and some advisers to the president wanted to wait to make the move public. Those advisers were stunned to see the news emerge from the White House on Tuesday night.

But for Mr. Mulvaney — who has never been fully empowered in the Trump administration, with “acting” always part of his title — it was a rare internal victory. And the announcement that a well-known fighter like Mr. Gowdy was joining the team hinted that the Trump operation was finally organizing around an impeachment strategy.

On Wednesday, Mr. Trump’s personal lawyers worked on a letter for Mr. Gowdy to sign to cement their agreement. Around 8 p.m. they released a statement announcing that Mr. Gowdy was formally on board.

“Trey’s command of the law is well known, and his service on Capitol Hill will be a great asset as a member of our team,” Mr. Trump’s personal lawyer Jay Sekulow said in the statement.

But within 30 minutes of that statement’s going public, Mr. Gowdy alerted Mr. Trump’s lawyers to a problem. His law firm, Nelson Mullins, had concerns that his work would involve lobbying activity. There was a discussion about whether Nelson Mullins could still be used, but a Trump adviser said that decision had been put off until January, when Mr. Gowdy’s lobbying ban concludes.