President Obama lashed out at Donald Trump on Tuesday, saying that the Republican nominee’s insistence that the election was being rigged undermines the country’s democratic traditions and demonstrates that he is not fit for the White House.

Obama accused Trump of “whining before the game is even over” and described Trump’s remarks as “unprecedented.”

“I have never seen in my lifetime or in modern political history any presidential candidate trying to discredit the elections and the election process before votes have even taken place,” Obama said.

Obama, who was appearing at a joint news conference with Italian Prime Minister Matteo Renzi, initially said he was reluctant to criticize Trump in such a setting. “I’m going to be a little more subdued in my discussions of the Republican nominee in this context than I might be on the campaign trail,” Obama said.

But the president, clearly troubled by Trump’s claims of a fixed election, quickly decided not to hold back. He described Trump’s allegations as a threat to American democracy and to the“integrity and trust” of the country’s civic institutions.

President Barack Obama and Italian Prime Minister Matteo Renzi leave after their joint news conference in the Rose Garden of the White House in Washington, Tuesday, Oct. 18, 2016. (AP Photo/Pablo Martinez Monsivais) (Pablo Martinez Monsivais/AP)

Over the course of a bitter presidential campaign, Trump has blasted not only Democratic nominee Hillary Clinton, but the media and even his fellow Republicans.

Obama dismissed Trump’s claims of election-fixing as baseless and impossible to carry out because balloting is overseen at the state level. In many swing states, such as Florida, a Republican governor oversees the process, Obama said.

“There is no serious person out there who would suggest somehow that you could even rig America’s elections, in part, because they are so decentralized,” Obama said. “And so I’d invite Mr. Trump to stop whining and go try to make his case to get votes.”

Obama also leveled criticism at Republicans who have continued to back Trump despite his frequent praise for Russian President Vladi­mir Putin as a strong leader. Earlier this week, Trump said that Obama was to blame for the tension between Washington and Moscow and indicated that if he won the election, he would meet with the Russian leader before Inauguration Day.

“The problem is Putin has no respect for Obama, at all, doesn’t like him and doesn’t respect him. And Obama doesn’t like Putin,” Trump said during a radio interview. “They insult him constantly. I mean, no wonder he can’t stand Obama and Hillary Clinton.”

Obama insisted that Putin was a leader who has violated basic human rights, disregarded the laws of war and trampled long-standing borders of his neighbors.

The president seemed especially mystified by Republicans who called for him to take a tougher stand against the Russian leader and still backed Trump.

Obama was a symbol for healing America’s racial wounds. His legacy will reflect a more complicated story.

“Mr. Trump rarely surprises me these days,” Obama said. “I am much more surprised and troubled by the fact that you have Republican officials who historically have been adamantly anti-Russian . . . now supporting and, in some cases, echoing his positions. It’s quite a reversal. You’ll have to ask them how to explain it.”

The president and the Italian prime minister spoke briefly about the Iraqi-led offensive to liberate Mosul, the largest city in northern Iraq, from the Islamic State. The offensive, which began Monday, is still in its early stages and could displace hundreds of thousands of Iraqis.

“No doubt, there will be instances where we see some heartbreaking situations,” Obama said, even as he praised the Iraqi government for its preparations to help those fleeing the battle.

The vast majority of the president’s news conference, though, was dominated by the election, which is less than a month away. Even the Italian prime minister conceded that the Trump vs. Clinton battle had dwarfed other news both in United States and Italy.

“I have a feeling and I think that rightly so our American friends are a little bit more interested in November 8,” Renzi said. “And so are we, might I add.”

Jose A. DelReal contributed to this report.