Cristiano Ronaldo's second-half treble gave Portugal victory in a dramatic World Cup qualifier which saw three players sent off at Windsor Park.
Bruno Alves volleyed in the opener and Gareth McAuley headed home an equaliser before Portugal striker Helder Postiga was red-carded for a headbutt.
Jamie Ward bundled in to put NI ahead but Chris Brunt was dismissed before Ronaldo made it 3-2 with two headers.
Ronaldo's free-kick sealed the win after Kyle Lafferty was sent off.
The hosts were aiming to build on their surprise win over Russia last month but fell behind on 16 minutes after a cagey opening to the game.
Alves, who headed the game's first chance wide five minutes earlier, made no mistake as he steered his volley beyond keeper Roy Carroll after a corner was cleared to the edge of the area.
Northern Ireland were rattled and Portugal began to look dangerous, though they were made to pay for failing to carve out any clear-cut chances.
The equaliser after 36 minutes was a classic set-piece move - Shane Ferguson provided an inswinging corner and a glancing header from McAuley bouncing before rising high into the net.
Portugal responded with Postiga forcing Carroll into a save with a low shot before Fabio Coentrao fired straight at the home goalkeeper.
But the visitors were reduced to 10 men two minutes before the break when Postiga was shown a straight red for a headbutt on McAuley, who almost netted his second of the night on the restart, with his audacious 35-yard chip sailing just over.
Ward put NI back in front with his first international goal on 52 minutes, turning the ball in from close range after Jonny Evans headed down from a Ferguson corner.
Michael O'Neill's team were in charge but things started to go wrong with Brunt's dismissal, for a second bookable offence after a poor tackle in the 61st minute.
Ronaldo's meagre contribution to the first half was a nutmeg on Steven Davis, but the Real Madrid forward showed his class with a clinical treble.
A near-post header from a 68th-minute corner brought Portugal level and another headed finish, into the corner from a deep cross, made it 3-2.
Substitute Lafferty took the dismissals tally to three, a straight red for a dangerous challenge on Joao Pereira.
And Ronaldo completed his hat-trick seven minutes from time, firing his 20-yard free-kick through the wall and beyond Carroll.
Portugal return to the top of Group F while Northern Ireland, already out of contention, will be without Brunt and Lafferty for Tuesday's qualifier against Luxembourg.