Media playback is unsupported on your device Media caption The BBC's Ben Wright reflects on the life of Ed Koch

Former New York City Mayor Ed Koch has died aged 88.

The brash, outspoken Democrat, who oversaw the city during some of its darkest years, had been in and out of hospital in recent months.

Koch became mayor in 1978 when New York was graffiti-marred and crime-ridden, and was credited with saving the city from near-bankruptcy.

He served three terms and afterwards remained active and popular, practising law, writing, and hosting a chat show.

New York Mayor Michael Bloomberg said the city had "lost an irrepressible icon, our most charismatic cheerleader" and announced that flags at all city buildings would fly at half mast.

Stroke

"Through his tough, determined leadership and responsible fiscal stewardship, Ed helped lift the city out of its darkest days and set it on course for an incredible comeback," Mr Bloomberg said.

Koch's great one-liners "It can never be as exciting as that first time" - before taking the oath of office after re-election

"So help me God, as the numbers were coming in, I said to myself, 'I'm free at last'" - describing being defeated in his bid for a fourth term in 1989

"The mayor is not a coward - and the mayor is also not a schmuck" - upon refusing to pose for a publicity photo with a white Bengal tiger

"If you don't like the president, it costs you 90 bucks to fly to Washington to picket. If you don't like the governor, it costs you 60 bucks to fly to Albany to picket. If you don't like me - 90 cents" - the price, then, of a New York subway token

"To the consternation of my enemies, I'm still alive" - Koch, aged 83, told the New York Daily News when he inadvertently set off a medical alarm in his home Obituary: Ed Koch

His funeral will be held at Temple Emanu-El, a Jewish synagogue, in Manhattan on Monday.

Even in his 80s, Ed Koch exercised regularly, but he had been battling various health problems, including heart disease, for a long time.

He suffered a minor stroke during his last term as New York mayor, and had a pacemaker inserted in 1991.

In 2009, he spent five weeks in hospital where he underwent quadruple bypass surgery and had a gall-bladder operation.

He was treated for anaemia in September and a respiratory infection in December, and earlier this month suffered from fluid build-up in his lungs.

Readmitted to hospital at the start of the week with shortness of breath, he was moved to intensive care on Thursday for closer monitoring of fluid in his lungs and legs.

He died at 02:00 local time (07:00 GMT) at New York-Presbyterian Hospital, his spokesman George Arzt said.

'Never a phony'

Ed Koch was born to Polish immigrant parents in the Bronx in 1924. After serving as a combat infantryman in Europe, he practised law before turning to a political career.

He was a US congressman before becoming mayor of New York city in 1978, a post he retained for three terms, until 1989.

His tough fiscal policies are credited with helping the city climb out of near-financial ruin to levels of enviable prosperity. But his critics say they also led to an increase in homelessness and racial tensions. Levels of HIV and Aids also soared during that time.

Corruption scandals blighted his third term, and in 1989, Koch lost the Democratic nomination for what would have been a record fourth term as mayor.

But there was no thought of retiring when he left office. He worked as a lawyer, made regular appearances on television and wrote a number of books.

Known for his outspoken and combative style, he once quipped: "I'm the sort of person who will never get ulcers. Why? Because I say exactly what I think. I'm the sort of person who might give other people ulcers."

The Rev Al Sharpton on Friday said that although they had disagreed on many things, Koch was "never a phony or a hypocrite. He said what he meant. He meant what he said. He fought for what he believed."