Traffic stops are how most citizens interact with law enforcement, and they tend to shape perceptions of the police. They rarely turn violent, but even peaceful encounters, like all but one of Mr. Castile’s, can lead to fines, searches, arrests and days of sitting in courtrooms that disproportionately affect poorer citizens.

In the seven states that collect the most comprehensive data on traffic stops, analysts have found often-striking disparities in how African-American drivers are treated. In two of the states, Connecticut and Rhode Island, changes in traffic enforcement followed.

There has been no such change in Minnesota. A state-commissioned study in 2003 found that minority drivers were more likely than white drivers to be both stopped and searched, even though officers found contraband more often when searching white drivers.

Myron Orfield, a University of Minnesota professor who was a co-author of the study, said that the findings strongly suggested widespread racial and ethnic bias in traffic enforcement.

More recently, a study by the American Civil Liberties Union found that African-Americans and Native Americans in Minneapolis were eight times more likely than whites to be charged with a low-level infraction, such as trespassing or loitering.

Mr. Castile’s encounters with law enforcement began when he was a teenager but never went beyond traffic infractions or misdemeanor charges of marijuana possession, which were dismissed. Nor was there ever any indication that he had been combative with the police. When a St. Paul officer pursuing a drug suspect stopped Mr. Castile’s car in 2005, the officer wrote that he knew him and that “normally Castile is very cooperative and friendly.”