The device-to-device (D2D) communication paradigm in 5G networks provides an effective infrastructure to enable different smart city applications such as public safety. In future smart cities, dense deployment of wireless sensor networks (WSNs) can be integrated with 5G networks using D2D communication. D2D communication enables direct communication between nearby user equipments (UEs) using cellular or ad hoc links, thereby improving the spectrum utilization, system throughput, and energy efficiency of the network. In this paper, we propose a hierarchal D2D communication architecture where a centralized software-defined network (SDN) controller communicates with the cloud head to reduce the number of requested long-term evolution (LTE) communication links, thereby improving energy consumption. The concept of local and central controller enables our architecture to work in case of infrastructure damage and hotspot traffic situation. The architecture helps to maintain the communication between disaster victims and first responders by installing multi-hop routing path with the support of the SDN controller. In addition, we highlight the robustness and potential of our architecture by presenting a public safety scenario, where a part of the network is offline due to extraordinary events such as disaster or terrorist attacks.