An ecosystem with anti-predator behavior is established in both deterministic and stochastic environments. This means that adult prey could attack weak predators. Bifurcation diagrams are used to analyze the deterministic case, while a tool called the most probable trajectory, defined by the spatial extreme point of the probability density function (PDF), is employed to explore the stochastic case. The Fokker-Planck equation is solved using the stochastic averaging method of energy envelope, which provides an analytical expression for the PDF. The results show that in the deterministic case, effective anti-predator behavior can dampen predator-prey oscillations and mitigate negative effects caused by the time delay. Additionally, it can accelerate the transient solution to reach a steady state and reduce the ratio of predator-to-prey densities in coexistence. In the stochastic case, effective anti-predator behavior can raise the noise threshold that leads to population extinction. Furthermore, it can also reduce the randomness of solutions. It's worth noting that appropriate anti-predator behavior can ensure that the most probable solution in the stochastic system approximates the solution in the deterministic system. Monte Carlo simulations verify the accuracy of these analytical results.