Railway level crossings pose a serious threat to the safety and mobility of drivers traversing them. Globally, a significant number of traffic violations occur annually at level crossings. This study proposes an optimization-based autonomous vehicle (AV) driving strategy to improve the traffic safety of AVs at level crossings. First, an optimization model considering the operational constraints is developed. The cost function of the proposed optimization-based driving strategy is the time difference between the time required by the train to reach the level crossing and the time taken by the AV to complete the whole crossing maneuver. Second, a MATLAB simulation model is developed to validate the proposed driving strategy. Simulation results show that the proposed driving strategy delivers optimized AV driving without stoppage. The comparative study also shows that the proposed method improves driving performance. For instance, when a train is 1 m away from the light signal while the AV’s initial speed is 36 km/h, the time required for the AV to reach the speed limit sign is about 0.44 s, while the time required by the train to reach the car block area is 0.13 s. Thus, the AV is forced to stop and then go after the train leaves the level crossing. Contrary to this, the proposed method allows a safe passage of the vehicle within 1.66 s without stoppage. Most importantly, the driving strategy is a collision avoidance strategy without unnecessary enforcement of stop-and-go when AVs have the chance of crossing safely. Consequently, the optimization-based driving strategy both improves traffic safety and reduces traveling time.