Josh Brownhill scored a fantastic late free-kick as Preston won 2-1 against rivals Burnley at Deepdale.