“Until all of us stand up and insist on holding public officials accountable for changing our gun laws, these tragedies will keep happening,” the former president wrote.
A shooting at a Walmart in El Paso, Texas, on Saturday killed 22 people, and a second shooting outside a crowded bar in Dayton, Ohio, early on Sunday killed nine people.
The suspect in the El Paso massacre posted a racist, anti-immigrant screed shortly before the attack, investigators say.
The motive of the Dayton gunman, who died in the attack, is not yet clear.
Mr Obama, like many presidents before him, has avoided pointed criticism of his successor.
But his comments left little doubt that he was referring to Mr Trump, who has spoken disparagingly about immigrants, calling them rapists and murderers, and has hit out an "invasion" at the Mexico border.
He also said he had directed the FBI to examine steps to identify and address domestic terrorism.
Mr Obama noted that the El Paso shooting followed a trend of “troubled individuals who embrace ideologies and see themselves obligated to act violently to preserve white supremacy”.
He advised Americans to also denounce the language of “leaders who demonise those who don’t look like us, or suggest that other people, including immigrants, threaten our way of life, or refer to other people as subhuman”.
Such language has “been at the root of most human tragedy throughout history”, he added, and has “no place in our politics and our public life”.