BERLIN — At least six people were shot dead at close range in a hospital in the Czech Republic on Tuesday before the gunman escaped and then turned his weapon on himself, in a rare mass shooting in the Eastern European country.

Police hunted for the 42-year-old for several hours before they tracked him to his vehicle, where he shot himself in the head as a police helicopter hovered overhead, according to regional police head Tomas Kuzel. He added that the gunman was using an illegal 9mm handgun.

At least two other people were injured in the attack, which came in the eastern city of Ostrava.

The director of the hospital, Jiri Havrlant, told the CTK news agency that the gunman had entered the waiting room and started shooting people at close range. Havrlant said one of the wounded was not yet out of danger.

The motives for the shooting remain unclear, and police said they had strengthened security at “selected soft targets” nationwide.

Prime Minister Andrej Babis described the incident as a “huge tragedy” and an “individual act” by the shooter.

It marked the country’s worst mass shooting since 2015, when a gunman shot eight people and himself in a restaurant in the town of Uhersky Brod.

The Czech Republic has some of the least restrictive gun laws in Europe, with firearms available to anyone who obtains a license. Gun owners can also apply for a concealed-carry permit.

The country launched a legal battle against European Union regulations introduced after the 2015 Paris attacks that made it harder for Europeans to buy semiautomatic rifles. Prague’s legal challenge was dismissed last week.

Ladka Bauerova in Berlin contributed to this report.