The advent of optogenetic tools has allowed unprecedented insights into the organization of neuronal networks. Although recently developed technologies have enabled implementation of optogenetics for studies of brain function in freely moving, untethered animals, wireless powering and device durability pose challenges in studies of spinal cord circuits where dynamic, multidimensional motions against hard and soft surrounding tissues can lead to device degradation. We demonstrate here a fully implantable optoelectronic device powered by near-field wireless communication technology, with a thin and flexible open architecture that provides excellent mechanical durability, robust sealing against biofluid penetration and fidelity in wireless activation, thereby allowing for long-term optical stimulation of the spinal cord without constraint on the natural behaviors of the animals. The system consists of a double-layer, rectangular-shaped magnetic coil antenna connected to a microscale inorganic light-emitting diode (μ-ILED) on a thin, flexible probe that can be implanted just above the dura of the mouse spinal cord for effective stimulation of light-sensitive proteins expressed in neurons in the dorsal horn. Wireless optogenetic activation of TRPV1-ChR2 afferents with spinal μ-ILEDs causes nocifensive behaviors and robust real-time place aversion with sustained operation in animals over periods of several weeks to months. The relatively low-cost electronics required for control of the systems, together with the biocompatibility and robust operation of these devices will allow broad application of optogenetics in future studies of spinal circuits, as well as various peripheral targets, in awake, freely moving and untethered animals, where existing approaches have limited utility.