In this paper, the impact of viral illnesses on the predator-prey relationship with an optimal control analysis is studied. An ecoepidemiological model of four compartments, namely, susceptible prey, susceptible predator, infected prey, and infected predator populations, in the interaction of the prey-predator system is formulated. The fundamental tenet of our ecoepidemiology model is that sick predators do not engage in predation. It is confirmed that the system’s solution exists, is positive, and is bounded. The system’s equilibrium points are determined and computed. Lyapunov functions and a linearizing form are used for local and global stability analysis, respectively. The next generation matrix approach is used to calculate the threshold value for diseased predators and prey at the disease-free equilibrium point. Optimal treatment options for vulnerable and infected populations are established by applying optimal control theory to the ecoepidemiology model of a prey-predator system. MATLAB software is utilized to obtain numerical simulations that validate the analytical outcomes. The optimal control problem simulations demonstrate that the number of infected populations in a given prey-predator system can be decreased by implementing control measures.