The Clogher Bullet, whose triumph in the British Supersport Championship last year secured his third British crown, qualified on pole on the S1000RR at the Bank Holiday meeting at the Cheshire circuit.
After a poor start, Farmer was holding fourth place in the early stages of the 15-lap race as Chrissy Rouse led the way on the IMR BMW followed by EHA Racing Aprilia riders Andy Reid and Joe Collier.
The lead changed hands as the race unfolded, with Farmer soon making good headway.
There was disappointment for Jordanstown rider Andy Reid, who was forced out of the race with a problem on the Aprilia on lap eight as he contested the lead with team-mate Collier.
Farmer was locked in a three-way battle for the victory and the Ulster rider managed to emerge on top on the final lap, denying Collier by only 0.062 seconds with Rouse finalising the podium places.
Carrick’s Alastair Seeley (WD-40 Kawasaki) and former Superstock 1000 champion Josh Elliott (Morello Kawasaki) from Ballinamallard finished seventh and eighth respectively.
Championship leader Billy McConnell ended the race in fifth place on the Buildbase Suzuki.
Farmer, who is carrying an injured hand after a crash in the official test at Oulton, is now only 11 points behind McConnell.
In the Dickies British Supersport Championship, Dublin’s Jack Kennedy won both races on the Integro Yamaha and now holds a 14-point lead at the top over Gearlink Kawasaki’s Ben Currie, who twice finished as the runner-up.
Eglinton’s David Allingham finished seventh in the Sprint race on Sunday but was out of luck on the Yamaha R6 in the Feature race with a DNF.
In the British Motostar class, Eugene McManus finished seventh twice, while Scott Swann was 20th and 18th respectively. Sam Laffins was 26th and 23rd.
Aaron Clifford took a strong fourth place in the National Superstock 600 race while Aaron Wright was eighth.
The Bennetts British Superbike Championship now embarks on a break until after the North West 200 and Isle of Man TT, with round four of the series taking place at Snetterton from June 15-17.
An official British Superbike test is scheduled next Thursday at Snetterton.