The men had fled the authorities in a van carrying 21 suspected migrants.
Hungarian police say they have arrested two suspected human smugglers after a dramatic gunfight and car chase near Budapest.
The suspects fired shots at Hungarian police from a van after refusing to stop near the town of Inarcs, police said in a statement on Monday.
A car chase then began around 20 kilometres southeast of the Hungarian capital.
The van had been carrying migrants and was forced to stop on the outskirts of the city before the suspects reportedly fled into a forest and fired more shots at police.
A police officer fired a warning shot and then returned fire. No one was injured in the one-hour pursuit.
Two men -- claiming to be Iraqi nationals -- were taken into custody in Budapest by Hungary’s counterterrorism agents and are due to be charged.
Police also said 21 suspected Syrian migrants were found in the van, which had Hungarian license plates.
Last week, a Bulgarian police officer was shot dead by an unidentified person at the border with Turkey.