Dominic Thiem edged error-prone Roger Federer 3-6 6-3 7-5 to win the BNP Paribas Open on Sunday, denying Federer a record sixth title in the desert.

Thiem trailed 4-3 and 5-4 in the third set before breaking Federer with a forehand winner to go up 6-5.

Thiem served out the two-hour match on Sunday that ended with another error from Federer, a forehand dumped into the net.

Federer was in the final for the third straight year and lost for the second year in a row.

He was beaten in a third-set tiebreaker by Juan Martin del Potro last year.

Federer won his 100th career title in Dubai recently.

Thiem had lost in his previous two ATP Masters 1000 finals.

But the 25-year-old Austrian’s solid serve held up against Federer as it had throughout the tournament.

Thiem was broken just four times out of 61 service games in the tournament.

He didn’t lose serve during his semifinal win over Milos Raonic, facing only one break point in that match.

Canadian teenager Bianca Andreescu upset Angelique Kerber 6-4, 3-6, 6-4 to win the women’s title.

Thiem and Andreescu earned $1.3 million each.

Federer and Thiem had split their four previous meetings, but Federer had won both of their hard-court matches without droppinga set.

He cruised through the first set in 36 minutes while getting broken for just the second time during his run to his ninth appearance in the final.

But Federer broke back in the next game and served out the set.

Thiem earned the only break of the second set in the fourth game, going up 3-1. Federer won just two more games in the set.

Both players were on serve in the third set until Thiem collected the only break.

Federer tried consecutive drop shots thatThiem retrieved for crosscourt forehand winners before the Austrian hit a winning forehand to lead 6-5.

Federer won just one point on Thiem’s serve in the final game.