Uber has secured its right to continue operating in London after a judge upheld its appeal against Transport for London (TfL).
The ride-hailing giant has been granted a new licence to work in the capital, nearly a year after TfL rejected its application over safety concerns.
It ends uncertainty for the 45,000 drivers who use the taxi app in London.
Westminster Magistrates' Court said Uber was now a "fit and proper" operator "despite historical failings".
One of the main concerns raised by TfL was a flaw in Uber's system that allowed unauthorised people to upload their photographs to legitimate drivers' accounts, which then allowed them to pick up passengers.
Westminster Magistrates' Court heard that 24 drivers shared their accounts with 20 others which led to 14,788 rides.
Uber's regional general manager for Northern and Eastern Europe, Jamie Heywood, said: "It was not what we would do now. It was inadequate, we could have done better."
Mayor of London Sadiq Khan said TfL was "absolutely right" not to renew Uber licence last year but acknowledged the company had "made improvements".
However, he added: "I can assure Londoners that TfL will continue to closely monitor Uber and will not hesitate to take swift action should they fail to meet the strict standards required to protect passengers."
Deputy chief magistrate Tan Ikram said he took Uber's "track-record of regulation breaches" into account but said it had made efforts to address failings and had improved standards.
"Despite their historical failings, I find them, now, to be a fit and proper person to hold a London PHV [private hire vehicle] operator's licence," he said.
The judge said Uber "does not have a perfect record but it has been an improving picture".
"The test as to whether [Uber] are a 'fit and proper person' does not require perfection. I am satisfied that they are doing what a reasonable business in their sector could be expected to do, perhaps even more."
The new licence will run for 18 months and comes with a number of conditions, allowing TfL to closely monitor Uber's adherence to the regulations.
Uber's Mr Heywood said: "This decision is a recognition of Uber's commitment to safety and we will continue to work constructively with TfL."
With 45,000 drivers on its books in London, Uber is a force to be reckoned with. But the body in charge of licensing in London has gone out of its way to take Uber on.
Transport for London (TfL) did manage to draw attention to a previous flaw in Uber's system which allowed unauthorised drivers to ferry people around. TfL piled on the pressure and, according to a judge, Uber's safety record has improved.
But when it refused to renew Uber's license, TfL knew that a judge would have the ultimate call. And at no point did anyone have to tell Uber's users in London that they couldn't order a cab.
Talking tough on Uber is one thing. But banishing it from a key European capital would carry significant consequences.
TfL originally refused to renew Uber's licence in September 2017. The company then won a 15-month licence by a judge in June 2018 after taking the case to court.
Uber was granted a two-month extension to its licence in September last year, but in November TfL decided not to grant it a new licence. At the time, TfL said it had "identified a pattern of failures by the company including several breaches that placed passengers and their safety at risk".
Uber appealed against the decision and was allowed to keep operating throughout the process.
Business campaign group London First said Monday's decision was "good news for millions of Londoners and visitors who rely on Uber to get around the capital".
However, the Licensed Taxi Drivers' Association said it was a "disaster for London".
"Uber has demonstrated time and time again that it simply can't be trusted to put the safety of Londoners, its drivers and other road users above profit," it said. "Sadly, it seems that Uber is too big to regulate effectively but too big to fail."
Uber is still awaiting a separate UK court ruling over whether its drivers should be classed as workers or self-employed.
The case, brought by two former drivers, could see Uber forced to compensate drivers across the UK for missed holiday pay, paid rest breaks and the national minimum wage.
Uber, however, says the "vast majority" of its drivers like being freelance.
The courts ruled in favour of the drivers in 2016 and Uber lost an appeal in 2018. A judgement on the firm's final appeal to the Supreme Court is expected soon.