BENGUELA, Angola — Two-time defending champion Egypt hammered eight-man Algeria 4-0 in a tense match to advance to the final of the African Cup of Nations on Thursday.

Hosni Abd Rabou converted a 37th-minute penalty and Mohamed Zidan doubled the lead with a left-footed shot from 15 yards (meters). Substitute Mohamed Abdel Shafy made it 3-0 in the 80th from a tight angle. Mohamed Gedo scored the fourth in injury time.

Rafik Halliche, Nadir Belhadj and goalkeeper Faouzi Chaouchi were all separately sent off.

In Sunday's final, Egypt will play Ghana, which beat Nigeria 1-0 in the other semifinal.

The win was Egypt's first over its north African rival in the continental championship. It also extended the Pharaohs' unbeaten run in the tournament to 18 games.

Algeria, which won their four previous meetings in the tournament, was the last to upset Egypt at Tunisia in 2004.

There was a major police presence at Benguela's all-seat stadium, where rival fans were kept apart from each other by a wall of police wearing riot helmets and wielding batons.

In November, three Algerian players were injured after their team bus came under attack from stone-throwing Egyptian supporters ahead of a World Cup qualifying match.

Algeria eventually beat Egypt in a November playoff to qualify for the World Cup.

But this night was all Egypt's, and within minutes of the final whistle, jubilant crowds of Egyptians poured into Cairo's streets, waving flags and beating drums. Young men lit up the night with impromptu flame throwers made of aerosol cans.

On the main road through the city along the Nile, cars with people hanging out of the window waving Egyptian flags sped by beeping their horns rhythmically.

While there was none of the violence that characterized the earlier loss to Algeria, police took no chances and sealed off the roads leading to the Algerian embassy.

For fans still smarting from Algeria's elimination of Egypt from World Cup qualifying, it was sweet revenge and the mood was ecstatic.

Halliche's late challenge on Emad Meteeb earned him a second yellow cared within 10 minutes and his dismissal. Benin referee Codjia Koffi pointed to the spot and Rabou fired home the only goal of the first half.

Zidan danced his way past a defender and unleashed a powerful shot into the top corner to extend the advantage in the 65th. Abdel Shafy took a pass from Zidan and curled it in from a difficult angle for the third before Gedo wrapped up the win with his late goal.

Belhadj was sent off in the 69th for fouling Ahmed El Mohamady while Chaouchi was ejected after picking up his second yellow card in the 87th.

Egypt's dominance began at a fast pace with the six-time champion creating chances in the opening minutes.

El Mohamady sent three dangerous crosses into the Algeria area inside the first two minutes. Zidan got to the end of one of another cross in the 6th but his shot went wide.

Mourad Meghni curled in a free kick for Algeria in the 3rd but it floated over the crossbar.

Algeria defender Madjid Bougherra made a powerful run and nearly netted from 20 yards (meters) in the 11th.

Egypt's first good chance to take the lead came in the 23rd when Zidan skillfully controlled the ball, laying it off for Meteeb, but Chaouchi made a diving save. (AP)