COPENHAGEN — Denmark’s prime minister conceded defeat Wednesday after general elections in which left-leaning parties made large gains that will probably put the Social Democrats back in power after four years in opposition.

Prime Minister Lars Lokke Rasmussen said he would resign Thursday from the post he has held since 2015.

Mr. Rasmussen’s center-right Liberal Party was getting about 23 percent of the votes, an improvement. But a big loss by the populist Danish People’s Party means the prime minister will no longer be able to muster a majority in the 179-seat Parliament.

The leader of the Social Democrats, Mette Frederiksen, said voters had decided a new direction for the country.