Lance Armstrong will pay $5 million to the federal government to settle a fraud lawsuit that contended he owed $100 million to taxpayers for doping while competing for a cycling team sponsored by the U.S. Postal Service.

The settlement was reached in an agreement announced Thursday with the U.S. Justice Department.

In addition to the $5 million to be returned to the government, Armstrong also agreed to pay $1.65 million to cover legal costs of Floyd Landis, a former Armstrong teammate and the whistleblower in the case, according to lawyers in the case.

The agreement was struck before the scheduled May 7 start of a trial over the civil case and ends the last legal action against Armstrong, a cancer survivor and cycling champion who in 2012 was stripped of his seven Tour de France titles and barred for life from Olympic sports.

Armstrong, 46, who recently listed his home in Austin for sale for $7.5 million, expressed delight at resolving the final lawsuit about his admission of doping, making peace with the Postal Service and putting the issue behind him.

“I am glad to resolve this case and move forward with my life,” Armstrong said in a statement. “I’m looking forward to devoting myself to the many great things in my life — my five kids, my wife, my podcast, several exciting writing and film projects, my work as a cancer survivor, and my passion for sports and competition. There is a lot to look forward to.

The Postal Service paid Armstrong’s team $32.3 million between 2000 and 2004 to ride under the service’s blue and white express delivery logo.

Shortly after Armstrong’s televised admission in 2013 that he had used banned performance-enhancing drugs for years, the Justice Department joined the whistleblower suit brought by Landis, seeking repayment of sponsorship fees plus damages totaling $100 million.

The Justice Department in a statement said the settlement showed “no one is above the law,” including Armstrong, whom government attorneys had called “a doper, dealer, and liar” in court filings and a contractor who profited from “years of broken promises.”

“A competitor who intentionally uses illegal (performance enhancing drugs) not only deceives fellow competitors and fans, but also sponsors, who help make sporting competitions possible,” said the acting assistant attorney general for the Justice Department’s civil division, Chad A. Readler.

Landis said the court battle “has been a difficult ordeal and public opinion was not always on my side, but it was the right thing to do, and I am hopeful that some positive changes for cycling and sport in general will be the result.”

The government alleged that Armstrong’s doping and violation of the rules of his sport nullified his value to the Postal Service brand.

Armstrong countered that he had delivered tens of millions dollars more in promotional benefits during his historic championship run than what the Postal Service had paid out.

Each side held to its view even as they closed out their legal battle.

“It always has been our position that Lance Armstrong misled the Postal Service,” said Thomas J. Marshall, Postal Service general counsel and executive vice president. The case demonstrated “the Postal Service vigorously defends our brand and our position as a trusted government institution,” Marshall said.

Armstrong said that he continues to view the lawsuit as “without merit and unfair” but that he has tried since 2013 “to take full responsibility for my mistakes, and make amends wherever possible.”

During his years riding for the federal sponsor, “I rode my heart out for the Postal cycling team, and was always especially proud to wear the red, white and blue eagle on my chest when competing in the Tour de France. Those memories are very real and mean a lot to me.”

The settlement closes a long and bitterly fought string of sports corruption cases brought by the Justice Department that focused on some of the country’s most celebrated athletes from the early 2000s, before the department turned recently to foreign targets including Russian athletes and the world soccer federation.

U.S. prosecutors abandoned a more than decade-long pursuit of baseball home run king Barry Bonds after an appeals court in 2015 overturned his lone conviction for obstruction of justice.

A federal jury in Washington acquitted pitcher and seven-time Cy Young Award winner Roger Clemens in early 2012 of lying to Congress about never having taken performance-enhancing drugs.

After the Clemens loss, prosecutors closed their criminal investigation into Armstrong without bringing charges.

But in late 2012, an extensive report from the U.S. Anti-Doping Agency — which included testimony by 11 former team members — concluded that Armstrong’s U.S. Postal Service Pro Cycling Team “ran the most sophisticated, professionalized and successful doping program that sport has ever seen” and named Armstrong the ringleader.

After years of denials, Armstrong admitted in a 2013 interview with Oprah Winfrey that he had taken banned substances and encouraged others to do so, while orchestrating a coverup of the team’s use of blood transfusions and substances including the hormones testosterone and erythropoietin, known as EPO.

Thursday’s settlement was reached through talks in mediation after U.S. District Judge Christopher R. “Casey” Cooper handed down a number of rulings ahead of the planned trial.

Among the rulings was one in February 2017 that let the lawsuit move forward but rejected the government’s claim that no sponsor would have backed Armstrong if the truth about his doping had been known.

The judge also ruled that U.S. authorities would have to demonstrate the financial harm the Postal Service claimed it suffered through the association with Armstrong.

Armstrong’s lawyers, led by Elliot Peters, argued that consultants to the Postal Service reported that the service reaped more than $100 million in marketing and other benefits from the cycling sponsorship a decade or so before Armstrong’s doping admission.

Armstrong’s team said the settlement amount was less than the government spent pursuing him, continuing what they say was USADA’s excessively harsh lifetime ban for doing for what a generation of cyclists at the Tour and athletes in other sports had done with far-less consequences.

Still, without a deal, Armstrong and his critics risked an ugly trial that could have stretched for weeks in Washington, spotlighted rampant doping in cycling and brought in dozens of figures who had been listed as possible witnesses, including former three-time Tour winner Greg LeMond , Postal Service riders George Hincapie, Tyler Hamilton, Jonathan Vaughters and Levi Leipheimer . Also called were former teammate Frankie Andreu and his wife, Betsy Andreu, who have contended that when Armstrong was recovering from brain cancer surgery in 1996, he admitted to his doctor in their presence that he used EPO, growth hormones and steroids.

The trial also threatened to reveal Armstrong’s confidential settlements in recent years with SCA Promotions and Acceptance Insurance, which sought repayment of $13 million in bonuses Armstrong had demanded after his Tour victories; and with the Sunday Times of London, which sought reparations for $1 million it paid Armstrong to settle a libel suit for publishing doping allegations about him, allegations that turned out to be true.

Landis filed his lawsuit in 2010 accusing Armstrong and other top American former teammates of doping after admitting to having spent $90,000 a year on his own doping regimen and giving up his Tour title.

Landis brought the lawsuit under the False Claims Act, which allows whistleblowers who expose fraud involving tax money to collect part of any money recovered. Under the settlement, he will receive up to 22 percent of the agreed upon amount, $1.1 million, in addition to legal expenses.

Armstrong has slowly tried to regain public trust and return to the sports world as a commentator, but the lawsuit with its potential $100 million penalty posed a debilitating financial blow.

He has a weekly podcast, “The Forward,” in which he interviews authors, movie stars and sports figures, and “Stages,” Armstrong’s audio and video analysis of last year’s Tour, was an iTunes hit. He was set to appear at a major one-day cycling race in Belgium three weeks ago, before pulling out citing a family emergency.

Armstrong’s attorney, Peters, said Armstrong has “a full and good life, ” with his children, including the eldest heading to college, and a longtime girlfriend, Anna Hansen, to whom he is engaged.

But Armstrong has estimated he lost $100 million by admitting to doping, as longtime sponsors and brands dropped him, including Nike, Michelob, Oakley eyewear maker and Trek Bicycle. The Livestrong Foundation, which supports people with cancer, also cut ties with Armstrong. It was established in 1997 as the Lance Armstrong Foundation.

Last month, Armstrong put his six-bedroom home in a historic Austin neighborhood up for sale, mainly for lifestyle reasons, his attorney said.

“But he does have to pull together some funds to pay the government over the next year,” Peters said.

“Even if Lance as an older guy could compete in an iron man triathlon or a couple of bike races, and people just saw him, and he could be seen in that context, it would help him,” Peters said. “But they really crippled him” by barring him from competing or taking any official role in a sanctioned event in an Olympic sport, Peters said.

“I hope that people can appreciate and accept him and the truth of his career and life — including what they learned of his performance-enhancing-drug use — as they have been able to do that with a lot of other people,” Peters said.