Vehicular ad hoc networks (VANETs) are a particular type of Mobile ad hoc networks (MANET) in which the vehicles are considered as nodes. Due to rapid topology changing and frequent disconnection makes it difficult to design an efficient routing protocol for routing data among vehicles. In this paper, a new routing protocol based on glowworm swarm optimization algorithm is provided. Using the glowworm algorithm the proposed protocol detects the optimal route between three-way and intersections. Then, the packets are delivered based on the selected routes. The proposed algorithm by using the glowworm swarm optimization algorithm, which is a distributed heuristic algorithm, assigns a value to each route from a source to the destination. Then a route with the higher value is selected to send messages from the source to the destination. The simulation results show that the proposed algorithm has a better performance than the similar algorithms.