Striker Younis Mahmoud scored in the 56th minute to effectively settle a bad-tempered match for Iraq, who overcame major hardship to reach the quarter-finals of the Asian Cup in China last month.
"Everybody expected Portugal to win, not us," said Mahmoud. "But we showed everyone we are a good team and that we can play good football and pulled off a surprise."
The game was marred by controversy, however, with Manchester United's Cristiano Ronaldo lucky to escape with only a yellow card after a blatant elbow on Mahmoud in the 19th minute that opened a nasty cut above the Iraqi forward's eye.
Ronaldo's team mate Luis Boa Morte was not so fortunate, the Fulham striker being sent off for a wild lunge on Iraqi left back Bassim Abbas six minutes into the second half.
Portugal, looking to restore some pride after their senior side were stunned by Greece in the Euro 2004 final, took the lead in the 12th minute in Patras thanks to an own goal from Haidar Jabar.
Iraq hit back to take a 2-1 lead through Emad Mohammed and Hawar Mohammed, only for Portugal to equalise on the stroke of halftime when Porto midfielder Jose Bosingwa volleyed home from the edge of the box.
But Iraq, forced to share a training pitch with grazing sheep in Baghdad, again demonstrated their resilience as the heavily bandaged Mahmoud swept home an Emad Mohammed pass after springing the Portuguese offside trap.
Substitute Salih Sadir added a fourth in injury time to complete Portugal's misery.
In the other Group D match, Costa Rica were held to a goalless draw by Morocco in Heraklio, Crete.
Meanwhile, Italy escaped a similar fate to Portugal as they fought back from two goals down to salvage a 2-2 draw with Ghana in Group B.
Striker Alberto Gilardino pounced in the 83rd minute to earn Italy a point after an absorbing game in Volos. Paraguay moved top of the group with a 4-3 victory over Japan in Thessaloniki.
The men's soccer is an under-23 tournament with three over-age players permitted per team. The Athens Olympics formally open on Friday.