Method and apparatus for transmitting data in device-to-device communication

The present invention relates to a device-to-device (hereinafter D2D) communication method in a wireless communication system. The D2D communication method of a terminal according to the present invention comprises the steps of: attempting a connection to a base station in order to request a resource for performing a D2D communication; when the connection attempt fails, selecting, on the basis of resource allocation information for a preset D2D terminal, a resource for performing the D2D communication; and performing a D2D communication using the selected resource.