The S&P 500 ended marginally higher for the week on Friday following a deal that ignited a sell-off among big retail and grocery companies.

Amazon announced it was buying Whole Foods for $13.7 billion, or $42 a share, sending their shares higher by 2.4 percent and 29 percent, respectively.

In turn, shares of Kroger, Costco, Target, SuperValu, Sprouts Farmers Markets and Dow-component Wal-Mart all dropped sharply following the news.

CFRA analyst Tuna Amobi said in a note that the deal "could presage a major long-term disruption of the grocery business by AMZN, as the company further leverages its technology, logistics and fulfillment infrastructure."

The consumer staples sector dropped 1 percent, capping gains on the S&P, which closed flat for the session.

The Dow Jones industrial average managed a record closing high despite Wal-Mart's 4.6 percent fall. The 30-stock index has also posted four straight weekly gains.

Investors also parsed through weaker-than-expected economic data on Friday, as housing starts and consumer sentiment figures both missed expectations.

"Overall, I think this is some of the initial optimism that drove the market higher cooling," said Mark Luschini, chief investment strategist at Janney Montgomery Scott.