The deal values Demandware at $75 a share, and represents a more than 56 percent premium over Tuesday's closing price of $47.99. Demandware was trading at $74.81 per share Wednesday.
The acquisition is Salesforce's largest to date, topping its $2.5 billion purchase of marketing software maker ExactTarget in 2013.
"With Demandware, Salesforce will be well positioned to deliver the future of commerce as part of our Customer Success Platform and create yet another billion dollar cloud," Salesforce CEO Marc Benioff said in a statement.
In an interview with CNBC's Jim Cramer on "Squawk on the Street", Benioff spoke about the competitive M&A landscape. "We're not winning every deal. This is just a deal we're actually able to get done. We're excited that we can actually get Demandware. And its tough to get deals done in this environment because everybody's positioning for growth for next year. I'm thrilled we got Demandware."
The deal, slated to close in July, is expected to increase Salesforce's 2017 revenue by about $100 million to $120 million, but reduce adjusted earnings per share by 7 cents.
Following the acquisition, Mizuho analyst Abhey Lamba downgraded Demandware stock to Neutral, predicting no other bidders will emerge. Lamba did raise his price target on the stock to $75 from $55. In a note to investors, Lamba said "as we expected, Demandware proved out to be a good strategic asset with Salesforce.com extending its reach into the e-commerce space."
Demandware stock, up nine days in a row, hit a 52-week high in its best day of trading ever. Before Wednesday, Demandware shares were down 11 percent for the year, while Salesforce had gained 7 percent. Salesforce shares were down 0.3 percent Wednesday at $83.45.