HOUSTON — Seven people were killed and at least 21 others were injured in a brazen daylight drive-by mass shooting in the West Texas cities of Midland and Odessa on Saturday, as a gunman drove on the highways and streets opening fire on residents, motorists and shoppers, the authorities said.

The attack at the start of Labor Day weekend terrified sister cities 20 miles apart with a combined population of 263,000, less than a month after gunmen killed 31 people in El Paso and Dayton, Ohio, in back-to-back massacres that stunned the nation and revived the debate in Washington over gun control.

The chief of the Odessa Police Department, Michael Gerke, said at a news conference on Saturday that the attack had begun after a traffic stop. The gunman fled the police and hijacked a postal truck, firing at civilians as he made his way into Odessa.

[The death toll in the West Texas mass killings climbed overnight. Read the latest.]

Three law enforcement officers and a toddler were among those wounded, before the police shot and killed the gunman, a man in his mid-30s, near a movie theater on the outskirts of Odessa. The police said the gunman’s motive was not immediately clear.