Device-to-device (D2D) communication system is considered one of the most effective technology directions for solving the spectrum scarcity problem in 5G wireless communication. In this study, an electronic relay is proposed to be utilised in D2D communication. The electronic relay is a hybrid cooperative relay consisting of compress and forward relay with and without coding techniques, decode and forward relay and amplify and forward relay with variable gain. The selection of the most appropriate one has performed automatically according to the feedback channel state information. Additionally, the multipleinput multiple-output (MIMO) electronic relay with the multiuser and massive MIMO destination is introduced. The closed formulas of the outage probability for both cellular user and D2D transmission are derived. Furthermore, the analytical discussions for the proposed electronic relay are executed. Extensive MATLAB simulation programmes are executed to study the performance of the proposed system and to compare it with the conventional one. Moreover, the average sum rate is derived in terms of a number of electronic relay antennas and the D2D density through cellular networks.