All smiles: Counselor to the President Kellyanne Conway and CNN's Jim Acosta outside the West Wing on March 25. (Jabin Botsford/The Washington Post)

CNN reporter Jim Acosta writes in a new book that his relationship with President Trump started off relatively cordial, but soon descended into denunciations that led to death threats from Trump’s supporters, armed security around the newsman’s family and an incident in which police were called to his home, guns drawn.

In “The Enemy of the People,” Acosta’s memoir about covering Trump, the journalist recounts a phone call from then-White House aide Hope Hicks after Trump’s first full news conference as president in February 2017. Acosta had questioned Trump at length.

“I just wanted to let you know that I spoke with the president and he wants you to know that he thought you were very professional today,” Hicks told him, ­according to Acosta. “He said, ‘Jim gets it.’ ”

Acosta wrote that he was somewhat baffled by the compliment at the time, especially because Trump had called CNN and him “fake news” in previous encounters. (Hicks declined to comment.)

It turned out to be the last time anyone in the White House would have nice things to say to Acosta, who came to embody the president’s efforts to demonize the news media. It also eventually made him a part of the story he was covering: The White House sought to revoke his press pass last November, touching off a closely watched court battle decisively won by CNN.

As Acosta reports in his book, published on Tuesday, criticism of him by Trump and White House press secretary Sarah Sanders has created a lingering sense of menace and dread, leading to an extraordinary set of personal-security measures.

Acosta reveals that he is regularly tailed by security guards whenever he covers one of Trump’s rallies. (CNN has previously asked reporters not to disclose this in press accounts.) At one rally, he notes, the network hired four off-duty police officers to protect him.

As death threats poured in during the days before the 2018 midterm elections, Acosta began speaking with the FBI and police detectives who were investigating the threats, and discussing whether to wear a bulletproof vest at Trump rallies. CNN gave him round-the-clock protection.

“I wasn’t sleeping much those days,” he writes in his book, subtitled, “A Dangerous Time to Tell the Truth in America.” “I was looking around corners as I walked home at night.” He wondered, “Should I carry a taser gun?”

At one point, someone “swatted” him, making a false report to police that a violent incident was occurring at his home. Police immediately descended on his residence with guns out, Acosta writes. No one was injured.

The danger became publicly apparent when a Trump supporter mailed pipe bombs to CNN’s office in New York and to Democratic figures, including former president Barack Obama, in October. A Florida man, Cesar Sayoc, has pleaded guilty to mailing the devices, none of which exploded.

In the aftermath, Acosta says Sanders “couldn’t find the decency to stop calling the press ‘the enemy of the people’ ” and failed to acknowledge that “it was the president’s rhetoric and the hostility he stoked at his events that had inspired the mail bomber in the first place.” (Sanders did not respond to a request for comment.)

Acosta — whose critics deride him as a “grandstander” or “showboat” in the White House press room — uses blunt language in the book to characterize public statements by Trump and his aides. He variously describes them as “lies,” “a fantasy,” and “bulls---” and criticizes Trump’s “fact-challenged grip on power” — unusually opinionated language for a reporter who continues to cover the White House.

His most forceful language arguably is employed in his description of the events surrounding the White House’s decision to take away his press credential last fall. The White House’s unprecedented action followed Acosta’s contentious exchange with Trump during a news conference and a brief physical altercation with a White House intern who had sought to take away his microphone.

He writes that it was “a disgusting smear” when Sanders tweeted that Acosta had been booted for “placing his hands on a young woman just trying to do her job” (video of the incident suggests the contact was incidental). He calls Sanders “a bad liar” for tweeting a sped-up version of that video in an effort to bolster the administration’s case.

“The endgame was obvious,” Acosta writes of his banishment. “ . . . The Trump people wanted me out and were willing to smear me to make that happen.”

After CNN sued the White House to win back his credential, Acosta worried that losing the lawsuit could be the end of his career, making him “radioactive” to any prospective employer. But he also mused about the larger consequences of an adverse judgment: “The White House could start ousting journalists it didn’t like. Governors and mayors across the country could start blocking reporters from official events. All those government officials would have to do, I worried, was point to CNN v. Trump, and that would be that.”

Eventually, a federal judge (a Trump appointee) ruled against the White House, saying it had violated Acosta’s due-process rights. He ordered the White House to restore Acosta’s pass.

As he rode away from the courthouse that day, Acosta writes that he had a triumphant reaction: “We beat Trump!”