Vehicular Ad-Hoc Networks (VANETs) deliver a wide range of commercial as well as safety applications and further motivate the advancements of Internet of Vehicles (IoV), Intelligent Transportation Systems (ITS), and Vehicles to Everything (V2X) communication. Despite their potential benefits, VANETs are susceptible to a variety of security attacks due to their open, distributed, and dynamic nature, which includes intrinsic protocol design issues. One such an infamous security attack is the Gray-Hole Attack (GHA), typically has two variants: Smart GHA and Sequence Number-based GHA. In Smart GHA, the malicious node behaves normally during the route discovery process, while in Sequence Number-based GHA, the malicious node starts misbehaving during the route discovery process. In either case, once the route is successfully established, it starts dropping the packets. In this paper, a novel security approach called ''Detection and Prevention of GHA'' (DPGHA) is proposed to detect and prevent both variants of GHA in Ad Hoc On-Demand Distance Vector (AODV) based VANETs. The approach is based on the generation of dynamic threshold values of abnormal differences of received, forwarded, and generated control or data packets among nodes and their sequence numbers. The proposed DPGHA is implemented and tested in NS-2 and SUMO simulators and its various performances are compared with the most relevant benchmark approaches. The results showed that the proposed DPGHA performed better than the benchmark approaches in terms of reduced routing overhead by 10.85% and end-to-end delay by 3.85%, increased Packet Delivery Ratio (PDR) by 4.67% and throughput by 6.58%, and achieved a maximum detection rate of 2.3%.