The men were whipped in Al-Shihr, a coastal town in Hadramawt province, after being summarily convicted of insulting God and consuming alcohol and drugs, the official said.
Dozens of people attended the flogging, which is said to follow the Islamic sharia law.
Witnesses said each man received between 80 and 100 lashes and that both screamed in pain.
The official said al Qaeda militants have been harassing residents by interfering in all aspects of their daily lives.
Al Qaeda in the Arabian Peninsula (AQAP) controls parts of Hadramawt, including provincial capital Mukalla, which they seized in April.
AQAP has exploited months of fighting in Yemen between Iran-backed rebels and the beleaguered Saudi-backed government to take advantage of the growing chaos.
The United States considers it to be the extremist group's deadliest global franchise and regularly targets its militants with drone strikes on Yemeni territory.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ