Our algorithmic understanding of vision has been revolutionized by a reverse engineering paradigm that involves building artificial systems that perform the same tasks as biological systems. Here, we extend this paradigm to social behavior. We embodied artificial neural networks in artificial fish and raised the artificial fish in virtual fish tanks that mimicked the rearing conditions of biological fish. When artificial fish had deep reinforcement learning and curiosity-derived rewards, they spontaneously developed fish-like social behaviors, including collective behavior and social preferences (favoring in-group over out-group members). The artificial fish also developed social behavior in naturalistic ocean worlds, showing that these embodied models generalize to real-world learning contexts. Thus, animal-like social behaviors can develop from generic learning algorithms (reinforcement learning and intrinsic motivation). Our study provides a foundation for reverse-engineering the development of social behavior using image-computable models from artificial intelligence, bridging the divide between high-dimensional sensory inputs and collective action.