The England international made his first appearance of the season when he replaced Carlton Cole as a 72nd-minute substitute at the Cardiff City Stadium.
Carroll then played a key role as the Hammers secured a crucial three points by setting up the second goal for Mark Noble in the third minute of injury-time.
The 25-year-old, who joined West Ham from Liverpool on a permanent basis in a £15m move last summer, has been plagued by an ankle problem for the last few months.
His comeback has been delayed on several occasions and he has visited a number of specialists before finally being given the all-clear to return to action to provide a welcome boost to the Hammers' attack.
A smiling Carroll told Sky Sports News after the game: "It's been an absolute nightmare if I am honest.
"I have been away to Belgium, Holland, I have been everywhere trying to fix it.
"Now I am feeling good and just want to play football and forget about it - put it in the past."
West Ham now face Carroll's former club at Upton Park next Saturday and the striker is already looking forward to that fixture.
He told guest West Ham TV interviewer Kevin Nolan: "It's going to be great to play Newcastle next week. I'll have a lot of family coming down and I can't wait to get back on the pitch after having 20 minutes today.
"I'm buzzing to be back, it's a great feeling to be back after being out for so long.
"Obviously I was a bit rusty, but I was happy to set up the goal at the end and I'll try to forget about the rusty bits."