In a sequence of Markov-dependent trials, the optimal strategy which maximizes the probability of stopping on the last success is considered. Both homogeneous Markov chains and nonhomogeneous Markov chains are studied. For the homogeneous case, the analysis is divided into two parts and both parts are realized completely. For the nonhomogeneous case, we prove a result which contains the result of Bruss (2000) under an independence structure.