Mr. Nadella and Mr. Benioff declined to be interviewed for this article.

A few months later, the two men had negotiated an agreement to make Microsoft’s Office 365 suite of applications work better with Salesforce’s online services, which they said business customers were clamoring for. They promised more collaborations to come. They began tweeting at each other like old friends.

At one point, Mr. Benioff offered to buy the Dynamics business that Salesforce competed with, but Mr. Nadella turned him down, according to two people briefed on the discussions.

The two companies stayed close and by the spring of 2015 their conversations evolved into another deal: Microsoft would acquire Salesforce. In May 2015, CNBC reported that the talks had fallen apart because Salesforce was demanding around $70 billion, about $22 billion more than the company’s market value at the time.

Several people briefed on the talks said that account was accurate, though two of them said another factor was that Mr. Benioff thought Microsoft was not respectful enough of his accomplishments in building Salesforce. It was unclear whether Mr. Benioff would be happy in a subordinate role at Microsoft after building Salesforce from the ground up, and it was equally hard to imagine a successful Salesforce without him.

Quickly, there were signs that Microsoft planned to get its act together in the C.R.M. business. As part of a broader shake-up, Mr. Nadella moved Dynamics under Scott Guthrie, one of Microsoft’s most respected engineering leaders. This telegraphed that it intended to go after Salesforce’s business.

“They’re serious in a way they haven’t been before,” said Charles Fitzgerald, an angel investor in Seattle and a former Microsoft manager who occasionally consults with the company.

Competition Heats Up

Salesforce did not sit idle. In November, it hired a former head of Dynamics, Bob Stutz, to oversee its data analytics products.