Fox News Channel said it is standing by Sean Hannity, its most popular on-air commentator, after the revelation that he has ties to President Donald Trump’s personal attorney, Michael Cohen, that he hadn’t disclosed on his program.

Mr. Hannity has been an ardent backer of Mr. Trump’s and on his show has been attacking government agents for raids last week on the office, home and hotel room of Mr. Cohen, who is under criminal investigation. He has offered such commentary without telling viewers of his relationship with Mr. Cohen.

The relationship was revealed in federal court Monday after a judge ordered Mr. Cohen’s lawyers to disclose the name of a client he was trying to keep secret. The hearing was centered on efforts by lawyers for Messrs. Cohen and Trump to review records seized by the Federal Bureau of Investigation before prosecutors are able to go through the files.

“While Fox News was unaware of Sean Hannity’s informal relationship with Michael Cohen and was surprised by the announcement in court yesterday, we have reviewed the matter and spoken to Sean and he continues to have our full support,” the cable network said in a statement Tuesday.

Fox News isn’t reprimanding Mr. Hannity for not disclosing his relationship with Mr. Cohen, a person familiar with the matter said.

Mr. Hannity has been attacking the FBI over the raids on Mr. Cohen, which were in relation to a $130,000 payment Mr. Cohen made to adult-entertainment actress Stephanie Clifford in return for her silence about what she said was a sexual encounter with Mr. Trump. White House representatives have denied that any sexual encounter took place between Mr. Trump and Ms. Clifford, known professionally as Stormy Daniels.

Lawyers for Mr. Cohen have said privileged documents were among the materials seized last week, and one of the lawyers, Steve Ryan, has called the use of search warrants “completely inappropriate and unnecessary.” Mr. Ryan added that Mr. Cohen “has cooperated completely with all government entities, including providing thousands of nonprivileged documents to the Congress and sitting for depositions under oath.”

On Monday, Mr. Hannity said he wasn’t a client of Mr. Cohen’s but said he considered the lawyer a friend and that the two had “brief discussions” about legal matters, mostly related to real estate. The talks, Mr. Hannity said, “never involved any matter between me and a third-party.”

Speaking on his radio show Monday, Mr. Hannity said he hadn’t paid Mr. Cohen legal fees but that “I might have handed him 10 bucks” and asked for attorney-client privilege on certain issues.

A mainstay of Fox News’s prime-time lineup for more than two decades, Mr. Hannity’s show is the most watched on the network, averaging 3.2 million viewers a night this month, according to Nielsen. He has spent months attacking the special counsel investigation into whether associates of Mr. Trump colluded with Russia’s alleged effort to meddle in the 2016 presidential election and also criticized the federal investigation into the Stormy Daniels matter.

21st Century Fox,
FOX -0.55%
the parent company of Fox News, declined to comment and referred inquiries to the cable network. 21st Century Fox and News Corp, publisher of The Wall Street Journal, share common ownership.