Cody McDonald fired the hosts ahead but two Smith headers from Jay Emmanuel-Thomas crosses saw City lead.
On-loan striker Smith's third came with a cheeky backheel after the break.
And although McDonald raced through for a second time to make it 3-2, Smith's stunning volley sealed an emphatic win.
The two-goal lead for next month's second leg at Ashton Gate was deserved after an impressive display by the League One high-flyers which puts them within reach of a Wembley final against either Preston or Walsall on 22 March.
But McDonald's early opener, which squirmed under away goalkeeper Frank Fielding, suggested a difficult evening against a side who sacked manager Peter Taylor on New Year's Eve and are struggling at the other end of the same division.
However, from the moment Fulham forward Smith, who has now scored seven goals in six starts for City, headed in after some great work by Emmanuel-Thomas the visitors looked in control.
A classy header made it 2-1 at the interval and Smith's hat-trick was sealed with a cute finish from a Scott Wagstaff cut-back.
McDonald ran through to fire his side's second but Smith's sensational, dipping volley restored the two-goal advantage for the two-time winners of the competition.
Bristol City manager Steve Cotterill told BBC Radio Bristol:
Media playback is not supported on this device
"Some of our attacking play was fantastic but it's been like that all season.
"A couple of our defensive lapses you can't be happy with but all in all, we have to be pleased with the performance.
"Some of the service Smith had was fantastic. I know he's got to take those chances, and he certainly did.
"We're pleased we've got him. He's a great lad and has integrated very well."
Matt Smith grabbed four goals as Bristol City fought back to beat Gillingham in a thrilling Johnstone's Paint Trophy area final first leg and take a big step towards Wembley.