Trump was speaking at the Mount Rushmore monument ahead of July the 4th celebrations marking the 250th anniversary of independence from Britain.
"We stand beneath the monument of these heroes, a true group of unbelievable people, and we rededicate ourselves to being a nation as big, bold, noble, and as great as these American giants, and that's not easy to do, but we're going to do it," Trump said at the granite mountain in South Dakota where the heads of four American presidents are carved.
"There is now a resurgence of the communist menace in our land, including from newcomers to our country who embrace ideas totally opposed to our way of life and our great success," he said. "We're not going to let this happen."
Trump's speech tied his anti-communist rhetoric to the anti-immigrant theme that fuelled his election and has been historically part of the criticism of communism in the United States. Trump at one point on Friday said the newcomers need to be expelled.
In New York City, Mayor Zohran Mamdani took a difference tone, casting the US as a nation of contradictions "working each day towards the perfection in which it was conceived."
"For generation after generation, we have been told that when the world has sent its people to our shores, it has not sent its best," Mamdani said. "Those ideals upon which our nation was built — they are strong enough to endure any authoritarian regime, but only if we reach for them."
Trump has been making points about gains by democratic socialists for a week now, but he made his most pointed and prolonged argument on that theme on Friday, as Americans grapple with persistent inflation and high gas prices since the start of the US-Israeli war on Iran.
Increasingly uneasy that the conflict could cost the party control of at least one chamber of Congress in November's midterm elections, Republican lawmakers have seized on a recent string of successes by left-wing Democratic candidates.
Four progressive candidates, including three democratic socialists, won competitive Democratic primaries in New York City last week and in Colorado on Tuesday. Progressive candidates have also won contests in Kentucky, New Jersey, Ohio, Pennsylvania and Texas.
Trump last week called their victories "the greatest threat to our country since its founding."
On Saturday, Trump was scheduled to address a crowd on the National Mall ahead of a massive fireworks show amid a searing heat wave that has disrupted Fourth of July celebrations across a large swath of the country.
At Mount Rushmore the temperature was a cool 18 degrees Celsius.