The former top cop in Washington and Philadelphia said Sunday that the country is “sitting on a powder keg” amid outcry over a number of fatal police shootings, including two last week that prompted nationwide protests.

And he fears that “some incident” will take place at the national political conventions later this month.

Charles Ramsey, the former D.C. police chief and one-time Philadelphia police commissioner, said on NBC News’ “Meet the Press” that this is a “volatile time” for the nation.

“We are sitting on a powder keg,” he said. “You can call it a powder keg. You can say that we’re handling nitroglycerin, but obviously, when you just look at what’s going on, we’re in a very, very critical point in the history of this country.”

How Philando Castile’s killing changed the way blacks talk about traffic stops

Ramsey’s comments came after police shootings in Louisiana and Minnesota, and then deadly sniper fire in Texas, where five officers were killed and several others were wounded.

"She has a poster, you have a shotgun," one protester yelled as Baton Rouge police rushed onto yards and sidewalks to arrest demonstrators on July 10. (Video: TWP)

On Tuesday morning, Alton Sterling was killed by a white police officer in Baton Rouge — a slaying captured on video by a bystander. The next night, Philando Castile was killed in Falcon Heights, Minn., as his girlfriend broadcast his final moments in real time on Facebook.

Dallas Police Chief David Brown said that the police-involved killings may have sparked the “delusions” of a man who opened fire on police officers Thursday night during a protest in the city’s downtown.

Brown told CNN it appears that the shooter, Micah Xavier Johnson, was trying to make police “pay for what he sees as law enforcement’s efforts to punish people of color.”

Fatal shootings by police are up in the first six months of 2016, Post analysis finds

A Washington Post analysis showed that last year, 990 people in the United States were fatally shot by police. So far this year, that number has reached at least 512 — an increase over the same period last year.

The Post’s Wesley Lowery reported Thursday:

The number of fatal shootings by officers increased from 465 in the first six months of last year to 491 for the same period this year, according to an ongoing two-year study by The Washington Post. This year has also seen more officers shot and killed in the line of duty and more officers prosecuted for questionable shootings.

He added:

Blacks continued to be shot at 2.5 times the rate of whites. About half of those killed were white, and about half were minorities. Less than 10 percent of all those killed were unarmed. One-quarter were mentally ill.

Ramsey, who was appointed by President Obama in 2014 to lead a White House policing task force, told NBC’s Chuck Todd that some crime rates are on the rise, explaining that, on average, there are about 13,000 murders in the United States each year but that “these are not shootings by police.”

“These are people killing people,” he said.

“Who do you think goes after the people responsible for these crimes? It’s the cops,” he added. “And we encounter a lot of very dangerous people out there on the street. So we can look at numbers in a variety of ways, but I think we need to keep it in context that police officers have a very challenging and often dangerous job. Now that’s not to say that we should not be mindful of the fact that we have some officers that use excessive force, that shoot people when it’s not totally justified. We’ve got to really address that and hold them accountable.

“But it is not a reflection of the department and policing at large.”

Ramsey also discussed the differences and discrepancies between police departments across the United States and said they need to be consolidated.

“There are approximately 18,000 departments in the United States,” he said. “In my opinion, far too many. And we need to look at a long-term goal. More regionalization, better training, more consistency in policy and procedures.

“In your larger cities, where you have a lot of diversity, obviously you have officers that are very accustomed to dealing with a variety of people. We still have parts in our country where that’s not the case. We need to bring people together, but we need more consistency in terms of the training that’s provided, the selection and hiring of individuals. All those kinds of things need to happen.”

He recommended cutting the number of departments in half “because you are always going to have these kinds of issues as long as you have this many departments with different policies, procedures, training and the like.”

Dallas police chief: Shooter seemed delusional, scrawled cryptic messages in blood

Ramsey said he worries that the topic may incite some issues at the upcoming Republican and Democratic national conventions.

The conventions, he said, “are going to be very, very challenging to handle. And I don’t think they are going to go without some incident taking place,” he said on “Meet the Press.”

“It’s unfortunate, but that’s what I personally think. I hope that’s not the case. But you’ve got too many people that are now with this extreme rhetoric and that is just not good for anybody. We need to come together, we need thoughtful people to sit down and engage in dialogue, but actually come up with solutions, not just finger-pointing and playing the blame game. That’s not helpful to anybody at all.”

He added: “It is a very, very volatile time that we’re in right now.”

This post has been updated.