Portugal went into the match having picked up only two points from their previous three qualifiers and having survived a huge scare on Friday when they needed a stoppage-time equaliser to draw 3-3 at Israel.
They were also without suspended talisman Cristiano Ronaldo for the clash, but Paulo Bento's men eventually overcame a stubborn Azerbaijan to boost their hopes of claiming a top two berth in Group F.
After a goalless first half Portugal received a huge fillip when home striker Rauf Aliyev was sent off after picking up two bookings in quick succession, and the visitors took advantage through headed goals from Alves and substitute Postiga in the final half-hour to claim the victory.
Portugal dominated the first half, but a mixture of indifferent finishing, good work by the Azerbaijan defence and the woodwork denied them the lead.
Alves came the closest in the 38th minute with a 30-yard free-kick which crashed back off a post, but he was not the only Portuguese player who must have felt the fates were conspiring against him.
Helder Postiga twice seemed certain to score, but he was first denied by a brilliant block by Rashad Sadygov in the 27th minute before then seeing seeing home goalkeeper Kamran Agayev somehow keep out his stoppage-time header with his feet.
Agayev also saved another effort from Postiga, while Miguel Veloso sent a 25-yard free-kick inches wide out as Portugal were thwarted in their bid for a first-half goal.
The visitors were back on the attack at the start of the second period, and Agayev was called into action once more to keep out Danny's shot.
Winless Azerbaijan were doing a valiant job of frustrating their opponents, but their hopes of seeing that through to the full-time whistle suffered a hammer blow in the 55th minute when Aliyev was dismissed.
The forward had only been booked minutes before when he was handed a second yellow card for a foul on Pepe.
Portugal needed just eight minutes to make their numerical advantage count.
Agayev had done well to parry an effort from Fabio Coentrao moments earlier but he was unable to keep out Alves' powerful header from Joao Moutinho's corner as a relieved Portugal finally got their noses in front.
Almeida, who replaced Raul Meireles soon after Aliyev was sent off, then wrapped up the points with Portugal's second 11 minutes from time with a close-range header.