"It is a huge honor to have been elected president of the UCI by my peers and I would like to thank them for the trust they have placed in me," Cookson said immediately after the results were announced inside the historic Palazzo Vecchio.
"The campaign to get to this point has been intense but I am under no illusion that the real work starts now. My first priorities as president will be to make anti-doping procedures in cycling fully independent, sit together with key stakeholders in the sport and work with WADA to ensure a swift investigation into cycling's doping culture."
Armstrong sent a one-word tweet that said, "Hallelujah."
Cookson also wants to set up a so-called "truth and reconciliation" commission to encourage riders, team officials and others with knowledge of cycling's doping past to come forward. He has warned that team managers who have been tied to or admitted doping during their careers as athletes could no longer have a place in the sport.
The 62-year-old Cookson also announced that as a result of the UCI vote he was stepping down as president of British Cycling, which he has led since 1997. And he acknowledged the bitter moments of the campaign but thanked McQuaid "for the contribution he has made to cycling during his long career."
"I wish him well in whatever he goes on to do," Cookson said.
McQuaid was first elected in 2005 and was seeking a third-four year term despite accusations that the UCI covered up Armstrong's doping during his tenure in charge. Armstrong was stripped of his seven Tour de France titles last year and banned from the sport for life after acknowledging that he doped.
"That's life, that's the way it goes. Congress has decided," McQuaid said. "They've elected a new president so good luck to the new president, good luck to the new management committee and let them go. ... I'm looking forward to a good holiday, which I badly need."
"I'll stay in cycling," McQuaid added. "I've been in it all my life. I'll find something. I'll find things to do, don't worry."
McQuaid's election status hinged on the interpretation of an article of the UCI constitution which states, "The candidates for the presidency shall be nominated by the federation of the candidate."
There was a long debate over McQuaid's eligibility, with numerous delegates speaking from the floor after lawyers addressed the case.
Eventually, Cookson got up and said: "We've had enough of this. I'm going to propose that we go straight to the vote between the two candidates."
And then the vote went ahead.
Earlier, there was a loud debate over an amendment that would have allowed an incumbent president to stand for re-election without nomination. It was met with loud resistance from the floor and a vote was held to delay considering the amendment for a year.
The vote ended 21-21 but a majority was needed so the amendment was not considered.
Pieter Zevenbergen, the president of the UCI ethics commission, said his committee examined five cases related to the election. Two of them, one concerning an alleged $34,000 bribe offered to the Greek federation and the other involving allegations against McQuaid from Russian cycling federation president Igor Makarov, could not be examined due to refusals of those concerned, he said.
"We are of the opinion that congress should consider these two (cases) before going to election," Zevenbergen said.
Many delegates appeared to agree with Zevenbergen, but Cookson's move to end the debate won out.
Follow Andrew Dampf at http://twitter.com/AndrewDampfAP