Mr. Stamos had successfully campaigned for Yahoo to encrypt the data flowing through its data centers. But when he pushed for end-to-end encryption — which ensures that only the parties in a conversation can see what is being said, leaving even Yahoo unable to read it — Ms. Mayer and other executives scoffed.

Some of Mr. Stamos’s other security proposals at Yahoo, such as resetting customers’ passwords after a breach, were rejected because the added inconvenience might encourage Yahoo customers to leave.

By then, Mr. Stamos had drawn the notice of Facebook executives. Some at the social network worried aloud whether he was too much of a firebrand to join the social network, according to three current and former Facebook employees who declined to be named because of nondisclosure agreements. But others argued that his activism was a benefit for the company.

Mr. Stamos joined Facebook in June 2015. From the start, the current and former employees said, he got off on the wrong foot with some executives, including Ms. Sandberg, over how best to police the platform. Facebook was increasingly grappling with cyberattacks from countries like Iran, whose hackers were caught trying to break into the accounts of State Department employees, and from Russia, the current and former employees said.

In a statement on Monday, Mr. Stamos said his relationship with Ms. Sandberg was “productive.”

After a breach of the Democratic National Committee in June 2016, Mr. Stamos pulled together a team to investigate Russian interference on Facebook. The findings pit him against executives in the company’s legal and communications groups. While Mr. Stamos argued to disclose more, others said that by proactively disclosing what they had found, Facebook had become a target of further public ire, according to seven current and former Facebook employees.