Device-to-device (D2D) communication permits direct communication between devices and thereby it provides performance gain for the traditional cellular network. In this paper, the problem how to allocate the transmission power efficiently is investigated and a distributed power control scheme is proposed for D2D communications. In this scheme, D2D user equipment (UE) can determine its transmission power dynamically for optimizing the link performance of the D2D link. To achieve this goal, firstly, an upper bound for the D2D transmitter density is derived based on which D2D UE determines its transmission power is on or off to avoid excess interferences and guarantee that each D2D link can achieve the link quality of service (QoS) on generally. In addition, for those D2D UEs transmitting data, the optimal transmission power is derived for a random D2D link which can optimize the successful transmission probability according to the link quality and the interference environment with few signalling exchange. Finally, some non-supported D2D links under hash environment are appropriately removed to reduce unnecessary interferences on other links and guarantee that an optimal power allocation solution exists for each D2D link. Simulation results show that compared with the fixed power scheme and the closed loop power control scheme, the proposed distributed power control scheme can improve the successful transmission probability under different wireless environments. Furthermore, compared with the closed loop power control scheme, the power consumption is reduced significantly (e.g. transmission powers for half of UEs can be reduced by above 84 %) by the proposed scheme.