The emergence of multimedia services has meant a substantial increase in the number of devices in mobile networks and driving the demand for higher data transmission rates. The result is that, cellular networks must technically evolve to support such higher rates, to be equipped with greater capacity, and to increase the spectral and energy efficiency. Compared with 4G technology, the 5G networks are being designed to transmit up to 100 times more data volume with devices whose battery life is 10 times longer. Therefore, this new generation of networks has adopted a heterogeneous and ultra-dense architecture, where different technological advances are combined such as device-to-device (D2D) communication, which is one of the key elements of 5G networks. It has immediate applications such as the distribution of traffic load (data offloading), communications for emergency services, and the extension of cellular coverage, etc. In this communication model, two devices can communicate directly if they are close to each other without using a base station or a remote access point. Thus, eliminating the interference between the D2D and cellular communication in the network. The interference management has become a hot issue in current research. In order to address this problem, this paper proposes a joint resource allocation algorithm based on the idea of mode selection and resource assignment. Simulation results show that the proposed algorithm effectively improves the system performance and reduces the interference as compared with existing algorithms.