Burnley bowed out of the Capital One Cup in controversy as Matt Taylor’s late penalty handed West Ham a quarter final place.
The tightest of games looked destined for extra time when Jason Shackell was ruled to have bundled over Kevin Nolan in the area, despite appearing to make contact with the ball.
And Taylor exacted the punishment with a clinical penalty to hand the Clarets their first defeat in two months.
A second, stoppage time penalty from Jack Collison, as Burnley went for broke, also compounded the misery as Keith Treacy was dismissed for a professional foul on the West Ham substitute.
Earlier, Kieran Trippier had come closest to breaking the deadlock with a free kick that struck the Hammers crossbar.
But it proved to be a frustrating night for Sean Dyche’s men, who can now put all their efforts into their league campaign.
Burnley made four changes to the side that emphatically defeated QPR at Turf Moor four days earlier.
Michael Kightly dropped to the bench in favour of former Hammers winger Junior Stanislas, while Kevin Long replaced Michael Duff at the heart of the defence.
Elsewhere, David Edgar and Brian Stock took the places of the injured Dean Marney and suspended David Jones.
And buoyed by that victory, the Clarets started on the front foot to force visiting keeper Adrian into two superb saves.
First the former Real Betis keeper turned Stanislas’s daisy-cutter round the post, and from the resulting corner he was again agile to turn over Danny Ings’ stinging shot on the turn.
A teasing Treacy cross from the right caused more panic in the Hammers defence as the Clarets continued to make all the early running,
West Ham had made nine changes to the team that drew with Swansea, with only skipper James Tomkins and Mohamed Diame surviving.
But the closest they came in an opening 35 minutes that saw them chasing shadows was a far post header from Tomkins that bounced straight to Tom Heaton in the Clarets’ goal.
Back came Burnley though and from a magnificent cross from Kieran Trippier, Sam Vokes had strayed a yard offside as his flick header cannoned back off the post with Adrian beaten.
And a confident half from the hosts ended with Adrian again in the action as he held onto Stanislas’s 30-yard shot.
Sam Allardyce made a change at the break, replacing Diame with Jack Collison.
But it was still the Clarets peppering the West Ham goal, as Stanislas curled over a free kick as he looked to make the headlines.
Finally, West Ham began to apply some pressure on the Burnley goal as the hour mark approached, and following a scramble in the Clarets box, Joe Cole had a goal chalked off for offside just before the hour mark.
Taylor then fizzed a cross just past a posse of inrushing white shirts as the visitors suddenly enjoyed their best spell of the night.
The introduction of Stewart Downing for Carlton Cole, as the hour approached, brought more ammunition to the Hammers ranks.
But this was now must more an even contest, with one goal always looking like it could prove crucial.
And Trippier was the width of a crossbar from providing it at the three-quarter mark, as his vicious, dipping free kick had Adrian beaten and smacked back off the woodwork.
And so it was left to a controversial decision to give the Hammers the lead.
Shackell was at full stretch as he looked to have nicked the ball off sub Kevin Nolan, and was incredulous as referee Robert Madley pointed to the spot.
Despite his protests, the Clarets skipper was booked – and the frustration compounded as Taylor stepped up to rifle his spot kick into the top corner.
Vokes almost levelled in the closing stages as he headed a corner straight into the arms of Adrian.
But the Hammers held firm - and when Treacy took out Collison from behind with Heaton stranded out of his area as he chased to clear, Collison struck home from 12 yards to end the Clarets’ seven-month unbeaten home run and book a last eight berth.
Burnley: Heaton, Mee, Long, Shackell, Trippier, Treacy, Edgar (Noble 91), Stock, Stanislas (Kightly 83), Vokes, Ings.
Subs: Lafferty, Duff, Howieson, Hewitt, Liversedge.
West Ham: Adrian, Tomkins (Nolan 71), Maiga, Taylor, O'Brien, Diame (Collison 46), C Cole (Downing 59), J Cole, Potts, Ruddock, Chambers.
Subs: Morrison, Spiegel, Tombides, Fanimo
Ref: R Madley
Att: 14,376 (2,070)