Phang Nga police chief Pol Maj-General Worawit Parnprung said the 21 escaped from an immigration office in Tambon Tham Namphud in Muang Phang Nga at 3am.
Worawit said the Rohingya used a saw to cut the iron bars of their detention cell at the immigration office and escaped in two groups.
The first group of 15 migrants escaped along a canal leading to Phang Nga Bay and the second group of six fled to the mountains.
Police later spotted three of them at a sheep farm. Authorities said one officer fired his sidearm in self-defence after the migrants assaulted him during the arrest.