over the weekend, amid accusations that he bears some responsibility.
An attack on a Walmart store in El Paso, Texas, left 20 dead, while nine died in a shooting in Dayton, Ohio.
Mr Trump said "perhaps more has to be done" to stop such attacks.
But critics said he was part of the problem, citing his anti-immigrant rhetoric and opposition to gun control.
A 21-year-old white man arrested over Saturday's shooting in Texas is believed to have posted an online document calling the attack a response to "the Hispanic invasion" of the state.
The motives of the Ohio gunman, who killed his sister and eight others on Sunday before being shot dead by police, are unclear.
Who were the victims?
El Paso unites in sorrow, song and strength
America reacts in shock to mass killings
Speaking to reporters, Mr Trump said mass shootings needed to be stopped.
"This has been going on for years, for years and years in our country and we have to get it stopped," he said.
He went on to link both attacks to a "mental illness problem", saying the gunmen were "very, very seriously mentally ill".
Investigators have not made any comments about the mental state of the two gunmen.
Texas prosecutors say the El Paso shooting is being treated as "a domestic terrorist case" and they are "seriously considering" hate crime charges.
The president is set to give a national address about the shootings on Monday.
What happened in El Paso?
The gunman opened fire on a crowded Walmart on Saturday with a semi-automatic rifle, and surrendered after being confronted by police officers outside the store.
The mass shooting, believed to be the eighth deadliest in modern US history, took place in a city where most of the population of 680,000 is of Hispanic descent.
In addition to the 20 fatalities, 26 people were injured in the shooting.
The Walmart, near the Cielo Vista Mall, was full of shoppers buying back-to-school supplies at the time of the shooting, and witnesses described scenes of chaos as customers fled for their lives.
#ElPasoStrong trends as city pulls together
Will gun laws change this time?
Soccer captain urges end to gun violence
Security camera images of the attacker show an armed man in a dark T-shirt wearing eye glasses and what appear to be ear protectors.
The victims have not yet been named by police, but Mexico's President Andrés Manuel López Obrador said six Mexican nationals were among the dead and seven others were injured.
The suspect has been named by US media as Patrick Crusius, a resident of the city of Allen, in the Dallas area, about 650 miles (1,046km) east of El Paso.
He has been charged with capital murder, meaning he could face the death penalty.
He is believed to be the author of a text posted on 8chan, an online message board frequently used by the far right, which says "this attack is a response to the Hispanic invasion of Texas" and talks about "cultural and ethnic replacement brought on by invasion".
The four-page document, reportedly posted some 20 minutes before police received the first emergency call from the Walmart, also expresses support for the gunman who killed 51 people in Christchurch, New Zealand, in March.
US cyber security firm Cloudflare said it would terminate 8chan as a customer following the attack.
"The rationale is simple: they have proven themselves to be lawless and that lawlessness has caused multiple tragic deaths," Cloudflare chief executive officer Matthew Prince wrote in a blog post.
Mexican Foreign Minister Marcelo Ebrard said the attorney general was considering litigation claiming that terrorism was committed against Mexicans in the shooting.
What happened in Dayton?
Connor Betts, 24, opened fire in a popular nightlife district in the early hours of Sunday morning.
Security camera footage shows dozens of people racing through the doorway of the local Ned Peppers nightclub.
Seconds later, the gunman is seen running towards the venue and being hit by police gunfire as he reaches the door.
Police said he had worn body armour and came carrying extra ammunition for his semi-automatic rifle with high-capacity magazines.
"Had this individual made it through the doorway of Ned Peppers with that level of weaponry, there would have been catastrophic injury and loss of life," said Dayton Police Chief Richard Biehl.
Officials said it was too early to speculate about motives for the attack.
But responding to questions about a possible racial element to the killings, Mr Biehl said there was nothing to suggest a "bias motive".
What has the reaction been?
The shootings have given renewed momentum to the gun control debate, with some lawmakers urging Congress to reconvene to pass new background check legislation.
The El Paso attack has also led to fresh scrutiny of the president's rhetoric. Some leading Democratic politicians have accused him of stoking white nationalism and inciting violence.
"He's an open avowed racist and is encouraging more racism in this country," presidential candidate and El Paso native Beto O'Rourke told CNN.
"Our president isn't just failing to confront and disarm these domestic terrorists, he is amplifying and condoning their hate," tweeted fellow Democratic presidential hopeful Pete Buttigieg.
Democratic Senator Bernie Sanders said Mr Trump's language "creates a climate which emboldens violent extremists".
But acting White House chief of staff Mick Mulvaney rejected the Democrats' allegations and attributed the attacks to "sick" individuals.
"There's no benefit here in trying to make this a political issue, this is a social issue and we need to address it as that," he told ABC.
Mr Trump, who has made curbing illegal immigration a priority, has previously made derogatory comments about Mexican migrants and has called large groups of migrants trying to reach the US an "invasion".
In recent weeks, he has been accused of racism after his attacks on members of Congress who are members of racial or ethnic minorities.
Last month, FBI Director Christopher Wray revealed that the agency had made about 100 domestic terror arrests since October - the majority of which he said were motivated by some form of "white supremacist violence".
There has been a number of other high-profile attacks linked to the far right in recent years, including two deadly shootings at US synagogues.