The Norwegian placed second on the stage to Team Sky's Wout Poels and leads the Dutchman by one second in the overall. Poels beat Boasson Hagen to the top of Hartside Fell by two seconds.
"On the last climb there were a lot of attacks and it was really hard, but the climb suited me, so I tried my luck with one kilometre to go," Boasson Hagen said.
"Unfortunately, I faded in the headwind on the last hundred meters and Wout Poels passed me for the win,” he said. "I'm happy though to take yellow and hope I can hold onto it. It would be nice for the team and Qhubeka to win the Tour of Britain."
A five-rider breakaway sneaked away in the early going of the stage, which had been advertised as the race’s most difficult. The 166 lumpy kilometres ended with the climb up Hartside Fell, where the General Classification was sure to be reshuffled.
"The team did a really good job today, especially Reinardt [Janse Van Rensburg], who rode strong to keep the break within sight," Boasson Hagen said.
The breakaway eventually split into two groups, with the final lead trio brought back into the fold with just under 10km remaining. Attacks throughout the final climb whittled the lead down to just three riders: Boasson Hagen, Poels and Steven Kruijswijk (LottoNL-Jumbo).
Boasson Hagen appeared to have made the winning move in the final 500 metres, but Poels was able to get back on terms and pass him for the win but without enough of a gap to take the rase lead.
The eight-stage Tour of Britain ends Sunday with a circuit race in London.