(CNN)Poland's Prime Minister Beata Szydlo resigned late Thursday and will be replaced by the finance minister, according to a statement from the ruling Law and Justice (PiS) party.

Shifting challenges at home and abroad necessitated a change to "correct the composition of the government, including its leadership," the party said in the statement.

As a result, the statement said, Szydlo is set to be replaced by Finance Minister Mateusz Morawiecki, a Polish banker.

Morawiecki was chosen to prepare the Law and Justice Party for a series of upcoming elections at the local and national levels in the next several years, Reuters reported, citing sources.

"Thank you for all your support and messages of thanks," Szydlo said in a statement on Twitter. "These two years have been an unbelievable time for me. To serve Poland and Poles has been an honor. Thank you."

Read More

According to a political analyst quoted in the Reuters report, Szydlo's ouster could have come about because the Law and Justice Party's leader, Jaroslaw Kaczynski, may have felt Szydlo was "too weak and that the government was seeded by internal conflicts and factional struggles."

"It is obvious that Jaroslaw Kaczynski is the leader of this camp and he is the one who distributes the cards, regardless of who is the prime minister," the analyst, Henryk Domanski of the Polish Academy of Sciences, said.