Massive machine-type communications (mMTC) is one of the main services delivered by the fifth Generation (5G) mobile network. The traditional cellular architecture where all devices connect to the base station is not energy efficient. For this reason, the use of device-to-device (D2D) communications is considered to reduce the energy consumption of mMTC devices. The main idea is to use nearby user equipment (UE) as a relay and establish with it D2D communication. However, the relay selection process also consumes energy, and this consumption can be significant compared to the energy consumed during the data transmission phase.In this paper, we propose a distributed energy-efficient D2D relaying mechanism for mMTC applications. This mechanism favors the selection of the UEs with low path loss with the mMTC device. Through mathematical analysis and simulations, we show that our mechanism allows a reduction of the total energy consumption of mMTC devices (up to 75% compared to direct transmission) when they have an unfavorable link budget. Moreover, our mechanism achieves almost constant energy consumption for a large range of UE densities and distances between the mMTC device and the base station.