Ronnie O'Sullivan came from behind to beat Stephen Maguire and win the German Masters in Berlin.

The former world number one, just one frame away from a first-round exit on Thursday, won Sunday's final 9-7 to land his first ranking title since September 2009.

Maguire fired three successive centuries on his way to a 5-3 lead at the Tempodrom and took the first frame of the evening session - but O'Sullivan finished strongest, rattling off five in a row to take control of the 30-year-old Scot.

Prior to this tournament, the penultimate event before the rankings cut-off point to decide which 16 players get automatic places at the World Championship, O'Sullivan was 16th and in danger of missing out on automatic qualification.

However, this success means his supporters can look forward to seeing him attempt to win a fourth Crucible crown.

O'Sullivan, who reached this final despite a bout of glandular fever, looked in good touch as he cantered to the opening frame, his break of 111 a taster of the superb fare to come in this best-of-17 contest.

However, Maguire - who whitewashed Shaun Murphy and John Higgins en route to the final - pulled level in the second frame after easing to a confident 130 break, the highest of the tournament so far.

He followed up with an equally assured 106 in the third and then produced a 128 to move 3-1 ahead after finding himself snookered from the break.

'The Rocket' made a decent start in the first frame after the interval, but when he broke down on 58 Maguire stole in to move 4-1 ahead.

A scrappy sixth frame went the way of O'Sullivan before a 55 helped Maguire restore his three-frame lead, but it was the three-time world champion who had the final say at the end of a breathless afternoon's snooker, a break of 75 giving him renewed hope heading into the evening session.

Maguire won the first frame after the resumption and potted five reds and five blacks at the start of the 10th but O'Sullivan hit back with a 96 clearance to reduce the gap to two frames, then picked up the next one to trail by just one.

Maguire was in first in the 12th frame with a break of 52 but missed the yellow and O'Sullivan cleared to the pink to level the match, punching the air after doing so.

It proved a key moment as he returned from the mid-session interval in inspired form, with a 67 break giving him the lead at 7-6.

Soon after it was 8-6 and he looked well placed to wrap up victory when he produced a break of 43 in the 15th frame, only to leave a black in the jaws.

Maguire, who led O'Sullivan 5-2 in last year's Welsh Open final but lost the contest 9-6, held his nerve to stem the tide and stay in the match with a clearance of 82.

There was an interesting twist at the start of the 16th frame when both players agreed to a rerack before a ball had been potted - and when they were respotted the cagey nature continued until O'Sullivan produced a break of 46.

Maguire got to within 17 points of his opponent but soon found himself needing a snooker - which O'Sullivan escaped from but went in off.

However, after Maguire had missed the blue, O'Sullivan wrapped up the 16th frame, which lasted nearly 40 minutes, and the match.