Samsung Electronics Co. agreed to buy a U.S. automotive technology manufacturer for $8 billion, the South Korean electronics giant’s biggest deal ever and its latest attempt to branch out beyond smartphones in the wake of its Galaxy Note 7 fiasco.

Samsung said Monday it would pay $112 a share in cash for Stamford, Conn.-based Harman International Industries Inc., an audio pioneer that has pushed aggressively into the automotive world. That is a 28% premium over Harman’s Friday closing price. The company’s shares surged 25%...