Self-configuration and autonomy are key features required for the next generation of gadgets and networks, since regular users are willing to have computationally enabled devices pervasively spread into their environment. Sensors are among the most promising devices into this new scenario. However, their low battery and processing power raise several issues to these autonomy requirements. This paper presents BiO4SeL (Bio-Inspired Optimization for Sensor Network Lifetime), a swarm intelligence-based algorithm to perform self-organization and optimization of lifetime by means of routing into a Wireless Sensor Network. Results show that BiO4SeL achieves its objectives when compared to similar approaches: ARAMA (Ant-based Routing Algorithm for MANETs), EAR (Energy-Aware Routing) and AODV (Ad-hoc On-demand Distance Vector).