We were on a military expedition when the Messenger of Allah ﷺ came to us and said, "You have been permitted to engage in mutah, so do so."Muslim adds, meaning the temporary marriage with women.
كنا في جيش، فأتانا رسول الله ﷺ فقال: إنه قد أذن لكم أن تستمتعوا فاستمتعوا. زاد مسلم: يعني متعة النساء.
Bukhari narrated it in the chapter on marriage (5118/5117) through Sufyan, and Muslim narrated it in (13:1405) through Shuba, both of them from Amr bin Dinar, who said, "I heard Hasan bin Muhammad narrating from Jabir bin Abdullah and Salama bin Akwa." They both mentioned it, and the wording given here is Bukhari's.