The migrants were found inside the trucks on Saturday at the border with Croatia, police said. The trucks had Serbian license plates.
Officers first discovered 13 people in one truck at the border before searching another belonging to the same company, where they found nine more.
Thousands of migrants have been stuck in the Balkans while seeking ways to move toward Western Europe. They often rely on people smugglers to get them over borders illegally.