Monsanto Co. agreed to sell itself to Bayer AG after months of haggling, in a $57 billion deal that would create an agricultural powerhouse and end the independence of one of the most successful and controversial companies in the U.S.

If regulators approve the deal, which was unveiled Wednesday, the German pharmaceutical and chemical conglomerate would inherit Monsanto’s market-leading position in seeds and crop genes. That would tilt Bayer heavily toward agriculture in a long-range bet on high-tech crops to sustain a growing...