The suspect, named by US media as Micah Johnson, 25, said he was upset about the recent police shootings of black people, Police Chief David Brown said.
Five Dallas police officers were killed and seven wounded during a march against the shooting of black men by police, officials say.
Three people are in custody.
Mr Brown said the suspect had been killed when police used explosives placed by a robot to end a tense stand-off in a building where he was holed up. Before that he had spoken to a negotiator.
“He said he was upset about Black Lives Matter [protest movement]; he said he was upset about the recent police shootings,” Mr Brown told a news conference.
“The suspect said he was upset at white people. The suspect stated that he wanted to kill white people, especially white officers.”
The mother of one of Alton Sterling’s five children denounced the Dallas killings, saying in a statement through her lawyer that “responding to violence with violence is not the answer”.
“Our hearts break for the families of the officers,” Quinyetta McMillon said.
President Barack Obama, who is attending a Nato summit in Poland, called it a “vicious, calculated and despicable attack on law enforcement”.
US Attorney General Loretta Lynch described events in Dallas as “an unfathomable tragedy”.
“Americans across our country are feeling a sense of helplessness, of uncertainty and of fear,” she said.