Tom Nichols goal inside the opening minute was cancelled out by a Toni Martinez brace and a strike from Martin Samuelson.
Tom Nichols managed to head home just twenty-five seconds into the encounter, as the striker managed to find room inside a congested area to head home a Byron Moore cross to give Rovers an early advantage in the tie.
The visitors scored a late equaliser in the first-half from the penalty spot, as Ryan Broom conceded a penalty for a foul on Ben Johnson. Toni Martinez dispatched the spot-kick to bring the Hammers back level before the break.
Following the interval, Martin Samuelson drove home a finish from close-range to put West Ham ahead, after a loose ball pinballed around the Rovers six-yard box.
Toni Martinez added his second goal of the game with fifteen minutes to go, as West Ham secured victory in the tie.
In naming the squad for the encounter, Manager Darrell Clarke opted to hand a first start to young Luke Russe, as the youngster was chosen to play along Stuart Sinclair in the heart of the Rovers midfield.
Sinclair took the armband for the evening, as Ryan Broom and Byron Moore were tasked working the opposite wings for the evening. Jonny Burn also made a return to action, as the centre-back was paired with Ryan Sweeney in Rovers back-four.
The game was only twenty-five seconds old when Rovers took the lead. A well-worked cross into a congested area from Byron Moore was headed into the net by Tom Nichols, as the striker scored his second goal in four days to put Rovers ahead early on.
Following the goal, the first-half didn't produce that the chances that early goal suggested it would. Sam Slocombe had to be alert to a long-range effort from Conor Coventry, which did move quite considerably through the night sky but didn't trouble the Rovers shot-stopper.
A quick purposeful run from Ryan Broom sliced open the West Ham defence midway through the first-half, but after finding Dom Telford on the edge of the area, the striker's effort couldn't beat West Ham 'keeper Nathan Trott, as he looked to place an effort inside the far-post.
Nathan Holland was lively for the visitors and managed to rob possession off Daniel Leadbitter down the right, as the defender was fortunate that his error didn't get punished, as Holland's pacy cross into the area narrowly missed Toni Matinez at the far post
West Ham restored balance to the scoreline just minutes before the break. Ryan Broom was judged to have fouled Ben Johnson inside the box after the pair collided at speed. Toni Martinez took the resulting spot-kick and held his nerve to send Sam Slocombe the wrong way to bring West Ham back level.
Just five minutes after the break, West Ham took the lead. Following a bouncing ball inside the Rovers area, Martin Samuelson was on hand to rocket home a low finish after Rovers failed to clear their lines, as Samuelson's shot nestled into the bottom corner.
Darrell Clarke replaced Nichols and Broom with Dunnwald and Cameron Hargreaves just past the hour mark, as Rovers looked to bring the scores back level.
It West Ham who forged an opportunity to extend their lead further, as Toni Martinez broke in behind the Rovers back-four and connected with a forcefully struck right-footed attempt. Sam Slocombe was quick to adjust his feet to deal with the striker's effort, diving to push Martinez's effort around the post.
Martinez did get his second goal of the game in the 75th minute, scoring from a tight angle to beat Sam Slocombe in a one-on-one situation, as West Ham took all three points on offer.
Rovers now face Swindon Town next Wednesday at the Mem in their final group stage fixture.
Rovers: Sam Slocombe, Daniel Leadbitter, Jonny Burn, Ryan Sweeney, Marc Bola, Stuart Sinclair (C), Luke Russe, Ryan Broom (65' Cameron Hargreaves), Byron Moore, Tom Nichols (65' Dunwald), Dom Telford.
Substitutes: Alexis Andre-Jr, Alfie Kilgour, Rollin Menayese, Cameron Hargreaves, Michael Kelly, Kenan Dunwald, Rhys Kavanagh.
West Ham: Nathan Trott, Sead Haksabanovic (72' Daniel Kemp), Toni Marinez (90' Jahmal Hector-Ingram), Domingos Quina, Nathan Holland, Josh Pask, Alex Pike, Martin Samuelson (72' Grady Diangana), Declan Rice, Ben Johnson, Conor Coventry.
Substitutes: Joe Powell, Anthony Scully, Ben Wells, Rosaire Longelo.