End-to-end learning of communications systems is a promising new paradigm for future communications, in which deep neural networks (DNNs) are implemented in the transmitter and receiver as an autoencoder architecture. However, due to DNN’s natural vulnerability to adversarial perturbations, the end-to-end communications system exhibits security and robustness issues in terms of adversarial attacks over the air. The common defensive method, known as adversarial training, is to augment training data with adversarial perturbations, but it is hard to cover all possible perturbations and also hurt the system generalization. In this paper, we propose a novel and defensive mechanism based on a generative adversarial network (GAN) framework 1 to achieve robust end-to-end learning of a communications system. We utilize a generative network to model a powerful adversary and enable the end-to-end communications system to combat the generative attack network via a minimax game. We show that the proposed system not only works well against white-box and black-box adversarial attacks but also possesses excellent generalization capabilities to maintain good performance under no attacks. The results also show that our GAN-based system outperforms the conventional communications system and the autoencoder communications system with/without adversarial training.