Wilfried Bony put Swansea ahead against the run of play, but Carroll, who missed the first three months of the season with an ankle injury, scored twice before teeing up substitute Diafra Sakho to lash in a late third.
Swansea finished the game with 10 men after goalkeeper Lukasz Fabianski was shown a straight red card for impeding Sakho shortly after Carroll’s second goal.
Victory took Sam Allardyce’s side up to third place, their highest position since 1999, ahead of fourth-place Southampton’s meeting with fifth-place Manchester United at St Mary’s on Monday.
Swansea, who have gone 58 years without a league win at Upton Park, remain eighth.
West Ham started with Carroll and Enner Valencia in attack for the first time and they dominated the early stages, with Kevin Nolan obliging Fabianski to save from Stewart Downing’s clipped free-kick.
But Swansea struck from their first attack of note in the 19th minute.
Jefferson Montero exchanged passes with Gylfi Sigurdsson and motored to the byline on the left before pulling the ball back for Bony to steer home his seventh goal of the campaign.
Bony threatened to add to Swansea’s lead with a potshot that whistled past the right-hand post, but after Fabianski had saved a header from Aaron Cresswell, the hosts equalised in the 41st minute.
After venturing forwards from right-back, Carl Jenkinson whipped an inviting cross to the far post and Carroll climbed highest to guide a fine header into the top-right corner.
West Ham introduced fit-again top scorer Sakho at half-time and continued to boss proceedings, although Bony almost restored Swansea’s lead on the hour with a vicious shot that grazed the crossbar.
The game was in the balance, but a two-minute spell mid-way through the second period tipped the momentum decisively in West Ham’s favour.
Carroll put the hosts ahead in the 66th minute, eluding Swansea’s markers to meet Downing’s drilled corner with a powerful header that visiting midfielder Leon Britton could only help into the roof of the net.
Moments later, Sakho was impeded by Fabianski, who had come rushing out of his goal, and although the Senegalese striker managed to roll a shot against the post, referee Chris Foy elected to send the Swansea goalkeeper off.
Swansea manager Garry Monk sent on reserve goalkeeper Gerhard Tremmel in place of Britton.
The German could only watch as Sakho skipped past Ashley Williams and despatched a right-foot shot that clipped the left-hand upright.
But Sakho made no mistake three minutes from time when he gathered a flick-on from Carroll before blasting past Tremmel to register his seventh league goal of the season.