The emerging fifth-generation (5G) technology towards Internet of Vehicles (IoV) provides numerous advantages, such as lower levels of latency, stable link connections, and support for high mobility. However, avoiding vehicle collisions in IoV is a challenging task due to routing Emergency Safety Messages (ESMs) without strict delay and reliability requirements. To address this issue, we propose a novel intelligent Software-Defined Networking-based Collision Avoidance (SDNCA) framework assisted 5G. Primarily, SDNCA performs the first algorithm that accurately estimates the Risk Severity (RS) value for each vehicle via training the proposed Risk Severity-Artificial Neural Network (RS-ANN) model through the implementation of federated learning among vehicles. The SDNCA framework applies the second algorithm to achieve three main objectives. First, it calculates the Quality of Service (QoS) of the ESM based on RS, Vehicle Speed (VS), and Risk Distance (RD). Second, it dynamically allocates 5G network and computing resources (gNB nr i and gNB cr i ) for three Virtual Networks (VNs) based on QoS, RD, and VS. Third, it selects the best route (best gNB) for routing the ESMs from the Source Vehicle (SV) to the Destination Vehicle (DV). To ensure effective forwarding for each ESM, SDNCA deploys the third algorithm at the selected gNB to schedule the ESMs considering their priorities and configures the gNB nr i and gNB cr i based on the OpenFlow control message received from the SDN. The real-time simulation results demonstrate that the SDNCA framework achieves the ideal values of 17% Network Overhead (NO) and Computational Complexity (CC), a remarkable 0% Collision Rate (CR), 18 ms End-to-End (E2E) Delay, and 89%-90% Packet (ESM) Transmission Reliability (TR) compared with the existing related research.