The engine choice was the same engine developed for the BMW M1, the S38B38 I-6. The original M1 engine was a 3.5 liter displacement, but the larger, heavier M5 Touring required more power and the bore and stroke of the engine was increased to its 3.8 liter displacement. It and the E34 M5 Sedan were the final two vehicles that used the S38.
Read the full article here