WASHINGTON — He has been called the shadow White House chief of staff, but Sean Hannity also sought to assist Paul Manafort as he defended himself from the special counsel’s investigation, according to court documents unsealed on Friday.

Mr. Hannity, a Fox News host who is a close ally of President Trump, advised Mr. Manafort on how to fight his prosecution in the court of public opinion, and also pressed for confidential details about the case, according to a compilation of hundreds of text messages exchanged between the men, made public as part of the winding down of the case. Mr. Hannity at times appeared to try to gauge whether Mr. Manafort, a former Trump campaign aide, might be poised to cooperate with investigators, and, if so, what he might tell them about Mr. Trump and his inner circle.

After Mr. Manafort’s former deputy, Rick Gates, pleaded guilty last year and agreed to cooperate with investigators, Mr. Hannity asked why Mr. Manafort did not “get a sweetheart deal like Gates.” Mr. Manafort responded that prosecutors “would want me to give up” the president or his family, especially his son-in-law and White House adviser, Jared Kushner. “I would never do that.”

The messages underscore the outsize role Mr. Hannity has played in Mr. Trump’s orbit. On his daily syndicated radio program and nightly Fox News show, he serves as a top supporter, leading the charge against Mr. Trump’s enemies. But Mr. Hannity also speaks regularly to the president about strategy and messaging, and the messages suggest he sought to play a similar role for Mr. Manafort, raising the specter that he could have helped the two parties coordinate their strategies, or at least given him real-time visibility into both sides’ thinking.