Hearts gave themselves the perfect send-off for Wednesday's Champions League qualifier in Bosnia thanks to Michal Pospisil's late winner.
He knocked the ball home 13 minutes from time after Bruno Aguiar's free-kick had come back off the crossbar.
Dunfermline finished with ten men when substitute Andy Tod was sent off for his second yellow card.
The hosts started well but lost new signing Noel Whelan after just five minutes when he limped off and was replaced by Tod.
Freddie Daquin had an early chance for the Pars but Steven Pressley blocked his 18-yard shot before Stephen Simmons' effort was deflected narrowly wide.
But it was Hearts that made the breakthrough after 14 minutes. Pospisil created the goal with a fine cross from the left which Roman Bednar hooked into the net from six yards.
The goal lifted Hearts and they dominated the rest of the first half and could have added to their lead. Dunfermline looked uncomfortable at the back with Bednar and Pospisil a constant source of concern.
Roddy McKenzie produced a tremendous save to keep out a long-range effort from Aguiar nine minutes from the break. The Bosnian midfielder tried his luck again before half-time with a 30-yard free-kick which McKenzie dealt with comfortably.
Hearts came within inches of a second goal six minutes into the second half when Neil McCann met Robbie Neilson's cross but the ball hit the underside of the bar.
Dunfermline equalised after 62 minutes when Simmons squeezed home a header at the back post from Scott Muirhead's corner.
Daquin then had a chance to give the Pars the lead when he took the ball around Craig Gordon but the angle was too tight for him and he was eventually crowded out.
But Hearts scored the winner 13 minutes from time when Pospisil stroked the ball home after Aguiar's free-kick had come back off the crossbar.
Tod was then dismissed after his second booking for a foul on Julien Brellier.