SEOUL, South Korea — A key ally of President Moon Jae-in of South Korea on Monday stepped down as justice minister, handing a victory to South Koreans who have been holding enormous rallies for weeks demanding his removal.

The minister, Cho Kuk, has been plagued by allegations of ethical lapses and financial wrongdoing in his family ever since Mr. Moon appointed him to the post in early August. Since then, prosecutors have opened an investigation into the accusations, and for weeks huge crowds have gathered in the capital, Seoul, to oppose Mr. Cho’s appointment.

Although Parliament refused to endorse Mr. Cho’s appointment, Mr. Moon formally made him justice minister last month, saying he needed Mr. Cho to push through his plans to overhaul the national prosecutors’ office, the same agency investigating Mr. Cho’s family.

People who supported Mr. Moon and Mr. Cho have since staged large counter-rallies, accusing prosecutors of using their investigation to topple Mr. Cho and scuttle Mr. Moon’s efforts to overhaul the prosecutors’ office . But the widening polarization has cost Mr. Moon heavily, with his approval ratings sliding in the wake of Mr. Cho’s appointment.