WARSAW — Two months after coming into office, Prime Minister Mateusz Morawiecki of Poland announced a sweeping reshuffle of the government on Tuesday, a move seen as an effort to punish political rivals while improving the governing party’s image abroad as it engages in a bruising battle with other European nations.

Mr. Morawiecki announced the dismissal of a third of his cabinet, including the foreign minister, the defense minister and several others with tense relationships with European leaders. He was then set to fly to Brussels, where he was scheduled to have a working dinner with the European Commission president, Jean-Claude Juncker.

In laying out the changes at a news conference on Tuesday, Mr. Morawiecki also reiterated Poland’s stance against Muslim immigrants. The country, he said, needed to be “safe at its external borders as well as inside the country.”

“Poland is a beautiful yacht sailing across the increasingly unknown seas and oceans,” he said. “But whether it docks safely in the port depends not just on strong cloths, but also our crew.”