West Ham won their first home game in six months after Portsmouth's Liam Lawrence was sent off.
The visitors led through a deflected Luke Varney effort but Matthew Taylor equalised with a free-kick.
Debutant Henri Lansbury put West Ham ahead before David Norris levelled. Lawrence then received a second yellow.
Mark Noble's penalty and Carlton Cole's header made it 4-2 before West Ham's Frederic Piquionne was sent off late on and Greg Halford scored a penalty.
It was West Ham's first game since the departure of Scott Parker to Tottenham on transfer deadline day and Sam Allardyce's men responded with a spirited performance in which Lansbury and goalkeeper Robert Green shone.
As well as giving Lansbury his West Ham debut, Allardyce named fellow new boys David Bentley and Sam Baldock on the bench.
But Portsmouth made the first impact in the eighth-minute as Varney's wayward effort from Lawrence's corner deflected in off Cole.
Just one minute later, West Ham were on level terms as Jason Pearce upended Cole on the edge of the box, allowing Taylor to curl in a free-kick with the help of a slight deflection.
West Ham looked invigorated by the equaliser and began dominating. Portsmouth had chances at the end of the first half though, as Green saved from a Pearce header and then brilliantly kept out Erik Huseklepp's low drive.
Green's hard work looked to have paid dividends eight minutes into the second half when Lansbury pounced on a loose ball in the box to fire a low shot that just bobbled over the line after taking a deflection off the underside of Pearce.
Portsmouth, though, returned to the attack undeterred and equalised through a Norris header that looked to have crossed the line before Benjani made sure with a header of his own.
The visitors continued to press but were reduced to 10 men in the 67th minute when Lawrence received a second yellow card for a lunge at substitute Bentley.
Six minutes later Lansbury earned the home side a penalty by flicking the ball into Pearce's hand, allowing Noble to strike home from the spot.
And West Ham wrapped up the victory in the 76th minute when Taylor fired in a superb ball that Cole managed to head home.
In stoppage time, substitute Piquionne was red-carded against his former club for raising his hands to Halford. It was Halford who then scored Portsmouth's consolation from the spot after Tal Ben Haim had been fouled.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.