Linfield chalked up their fourth straight Irish Premiership win thanks to second-half strikes from Jamie Mulgrew and Andy Waterworth.
Alvin Rouse saved from a Waterworth shot as the Blues took control although the hosts were dangerous on the break.
Mulgrew poked in to put Linfield ahead on 68 minutes before Waterworth lobbed Rouse to make it 2-0 at Ferney Park.
Andy Crawford headed in with two minutes left but the Blues held on to move three points off the top.
Linfield dominated the first half but they were frustrated by resolute defending from a determined Mallards team.
Rouse made a series of excellent saves and he denied Waterworth and Mulgrew in the second half before the Blues made the breakthrough.
Waterworth's run and cross from the left set up midfielder Mulgrew to stab home from six yards.
The striker netted his fourth goal in two games when he chipped in 10 minutes later while Crawford's late header made it a nervous finish for the Belfast visitors.
"I was delighted with the performance and we thoroughly deserved to win against tough opposition," said Linfield boss David Jeffrey.
"The whole attitude of the team pleased me - talent is nothing if it is not backed up by hard work and commitment.
"We came out flying and played some really good stuff and at half time I just told the team to keep battling.
"It was a piece of brilliance from Andrew Waterworth, who works tirelessly for the team, to make the goal for Jamie."