Germany international Kevin Volland was in more clinical form and gave Hoffenheim a 43rd-minute lead by rounding the keeper and slotting home, after Firmino had done the donkey work with a 50-yard run.
Volland was denied a second shortly after the break by Timo Hildebrand, while Frankfurt came close through Alexander Meier and Seferovic and eventually got their equaliser when Aigner guided into the bottom corner on 58 minutes.
Hoffenheim brought on Adam Szalai in a bid to try to regain their lead and the substitute was in the right position to tap home the rebound to a Volland shot from a tight angle.
Frankfurt were determined not to let their opponents leapfrog them in the table and levelled things for a second time when Seferovic poked home from close range at the second attempt for his sixth of the season.
However, a moment of magic from Szalai, who back-heeled the ball through a congested penalty area during a goal-mouth scramble following a corner, allowed Firmino to snatch the hosts a 3-2 victory.
The result ends Frankfurt's three-match winning run and sees Hoffenheim climb above them to seventh in the standings.