Swarm behaviors in nature have inspired the emergence of many heuristic optimization algorithms. They have attracted much attention, particularly for complex problems, owing to their characteristics of high dimensionality, nondifferentiability, and the like. A new heuristic algorithm is proposed in this study inspired by the prey location and communication behaviors of electric fish. Nocturnal electric fish have very poor eyesight and live in muddy, murky water, where visual senses are very limited. Therefore, they rely on their species-specific ability called electrolocation to perceive their environment. The active and passive electrolocation capability of such fish is believed to be a good candidate for balancing local and global search, and hence it is modeled in this study. A new heuristic called electric fish optimization (EFO) is introduced and compared with six well-known heuristics (simulated annealing, SA; vortex search, VS; genetic algorithm, GA; differential evolution, DE; particle swarm optimization, PSO; and artificial bee colony, ABC). In the experiments, 50 basic and 30 complex mathematical functions, 13 clustering problems, and five real-world design problems are used as the benchmark sets. The simulation results indicate that EFO is better than or very competitive with its competitors.