WASHINGTON — President Obama responded with passion and frustration on Tuesday to the violence that has rocked Baltimore and other cities after the deaths of young black men in confrontations with the police, calling for a period of soul-searching about what he said had become a near-weekly cycle of tragedy.

Speaking from the White House Rose Garden, Mr. Obama condemned the chaos unfolding just 40 miles north of the White House and called for “full transparency and accountability” in a Department of Justice investigation into the death of Freddie Gray, the young black man who died of a spinal cord injury suffered while in police custody.

He said that his thoughts were also with the police officers injured in Monday night’s unrest in Baltimore, which he said “underscores that that’s a tough job, and we have to keep that in mind.”

But in a carefully planned 14-minute statement during a news conference with Prime Minister Shinzo Abe of Japan, Mr. Obama made clear that he was deeply dismayed not only by the recent unrest in several cities but also by the longstanding yet little-discussed racial and societal forces that have fed it.