David Pecker, the chief executive of the company that publishes the National Enquirer, was granted immunity by federal prosecutors for providing information about Michael Cohen and President Trump in the criminal investigation into hush-money payments for two women during the 2016 presidential campaign, according to people familiar with the matter.

In exchange for immunity, Mr. Pecker, the CEO of American Media, Inc. and a longtime friend of Mr. Trump, has met with prosecutors and shared details about payments Mr. Cohen arranged...