In their Group G opener at the Camp Nou on Tuesday, Messi netted from the penalty kick spot in the first half for his 116th career goal in the competition.
The lively Ansu Fati added a second, while Philippe Coutinho grabbed another goal early in the second half.
But FC Barcelona defender Gerard Pique was dismissed for impeding Tokmac Nguen, leading to a penalty kick for the visitors that was converted by Igor Kharatin.
Any thoughts of a dramatic comeback were quashed, though, as 17-year-old Pedri netted his first FC Barcelona goal after arriving from second-tier Las Palmas at the start of the season.
Dembele added the fifth late on.
The Catalan side moves above Juventus on goal difference at the top of the table after the Italian champions won 2-0 away at Dynamo Kyiv earlier on Tuesday.
The pair meet in Turin on Oct. 28.
FC Barcelona coach Ronald Koeman left stalwart midfielder Sergio Busquets and striker Antoine Griezmann on the bench, perhaps with one eye on Saturday’s ‘El Clasico’ against bitter rivals Real Madrid.
Ferencvaros are in the group stages for the first time in 25 years and had their moments.
Striker Nguen produced a mazy run and fine finish, but his effort was correctly ruled offside, while Brazilian midfielder Isael struck the angle of post and crossbar with a fierce drive.
Messi handed his side the lead after he both won and converted a penalty kick, bringing up another milestone in his career.
Former Manchester United winger Ryan Giggs is the only other player to net in 16 UEFA Champions League seasons, though the run was not consecutive.
Fati then beat the offside trap from Frenkie de Jong’s lobbed pass and steered the ball into the net on the volley.
Then, Coutinho profited from intricate build-up play by Messi and Fati to score.
Ferencvaros, however, created what looked like being a nervous final 20 minutes as Pique could not handle the pace of Nguen and hauled the striker back in the box.
He saw red for his indiscretion as Kharatin easily converted the spot-kick.
But late goals from substitutes Pedri and Dembele against the tiring visitors sealed a satisfactory night for Koeman.(Reuters/NAN)