The assault on the coastal district of Dhubab, just 30 kilometres north of the Bab al-Mandab strait linking the Red Sea and the Indian Ocean, came after the government sent reinforcements from its headquarters in Aden.
The general was killed by rebel sniper fire, the military sources said.
The government and its allies in a Saudi-led coalition recaptured the strait in October 2015.
But the rebels still control nearly all of Yemen's Red Sea coast to the north, posing what the coalition says is a threat to international shipping.
The loyalist offensive failed to dislodge the rebels from their positions as they put up fierce resistance, leaving many wounded on both sides, the commander said.
The Yemeni conflict has killed more than 7,000 people since the coalition's military intervention began in March 2015, according to the United Nations.