Singapore’s former Deputy Prime Minister Tony Tan, 71, was declared the city-state’s newly elected President early Sunday after the government’s preferred candidate had to overcome a stunning challenge by a political maverick.

Widely perceived as the man to beat in the non-partisan election, Tan won 35.19 per cent of the votes in a ballot, which was seen as a further test of support for Prime Minister Lee Hsien Loong’s People’s Action Party (PAP).

Following a recount of the votes due to a knife-edge fight, Tony Tan held a slight edge of 7,269 votes over Tan Cheng Bock, 71, a medical doctor and former PAP legislator, said the elections department.

His closest rival ended up with 34.85 per cent of the votes, while two other presidential hopefuls went out of the race earlier.

In first comments, political observers said the result was sobering for all parties. Tan won a six-year term as head of state and will succeed outgoing president S.R. Nathan, 87.

Although Singapore Presidents have a largely ceremonial role and mainly act on the advice of the Cabinet, the presidential race turned out to be unexpectedly fierce.

The ballot followed a heated campaign with calls for stronger checks on the PAP, which has ruled Singapore with a firm hand ever since 1959.

Of all four contenders, Tony Tan was the one with the closest ties to the PAP as he served as Minister at the helm of key portfolios like Education, Finance, and Defence.

His performance in the polls was therefore closely watched as a yardstick of voter discontent with the PAP government, which held power in the May general election with the worst result in decades, winning 60 per cent of the votes.

The party was punished at the polls as many voters expressed anger over the handling of hot topics like the influx of foreigners and rising costs of living.

Following the general election, Prime Minister Lee and the PAP pledged a more humble style of government, noting that Singapore’s electorate wanted more diversity.

Tan echoed those calls, saying that “We can cherish many voices in one Singapore.” However, while the other candidates said they would seek a more active role as a President or even seek to transform the post into a platform to challenge the government, he sought to quell all calls for a more independent presidency.

“Policies are debated in Parliament and implemented by the government,” he said.