This act was a direct service to the King, as Farquaad was the one who had asked Shrek to rescue Fiona, offering him a deal in return for his services.
While Shrek didn't directly serve the King in a more traditional sense, saving Fiona from Farquaad was essentially a favor to the King, as Farquaad was attempting to marry Fiona in order to claim her kingdom and rule it himself.