This paper is concerned with a stochastic Leslie–Gower Holling-type II predator–prey system with regime switching and prey harvesting. Firstly, sharp sufficient criteria for the extinction and the existence of a unique ergodic stationary distribution of the system are established, and the convergence of transition probability of the solution to the stationary distribution is estimated. Then, sharp sufficient criteria for the existence of optimal harvesting strategy are obtained. Some critical influences of random perturbations on the existence of a unique ergodic stationary distribution, extinction and optimal harvesting strategy are revealed. Finally, several numerical simulations are presented to illustrate the theoretical results.