The prospects for Mr. Moon’s party did not look good​ until less than two months ago​. He and his party’s approval ratings had been slumping​ over a decaying job market, stalled diplomatic efforts with North Korea and scandals involving Mr. Moon’s closest allies.​ ​The coronavirus ​had initially appeared to work against Mr. Moon and his party​​, as they were criticized for underestimating the threat.

But their political fortune shifted once Mr. Moon’s government ​began ​testing large numbers of people in February to screen out patients for isolation and treatment. ​South Korea, once home to the world’s second-largest outbreak, with as many as 813 new cases a day, has reported fewer than 40 new ​patients a day in the past week​.

As President Trump​ and other foreign leaders called Mr. Moon, asking South Korea for supplies of test kits or advice in handling the outbreak, his popularity rebounded​ at just the right time.

During the campaign​, Mr. Moon’s conservative rivals accused him of coddling the nuclear-armed North Korea and undermining the alliance with Washington by taking Seoul too close to Beijing, criticisms which Mr. Moon ​strongly rejected.

With their victories on Wednesday, South Korea’s liberals​ achieved more political​ clout than they have ever held.​

Their ascent began when former President Park Geun-hye, a conservative, was impeached and then ousted on corruption charges in 2017. Mr. Moon won the presidency in an election that same year, becoming the first left-leaning president in nearly a decade. In 2018, his party won all but three of the 17 contests for big-city mayors and provincial governors.

“By taking over the Parliament as well, the progressives complete replacing the conservatives as the mainstream political force​ in South Korea​,” said Park Sung-min, head of Min Consulting, a political polling company in Seoul.​