Outgoing House Speaker Paul Ryan lamented the country's “broken politics” and partisan fights during his farewell address on Wednesday, while also praising the achievements of Congress during the chaotic three years he held the gavel.

“We have taken on some of the biggest challenges of our time, and made a great and lasting difference in the trajectory of this country,” Ryan, R-Wis., who will likely be replaced by Democratic Leader Nancy Pelosi in the new session, said during his speech at the Library of Congress. “Certainly one Congress cannot solve all that ails us. Not every outcome has been perfect.”

Ryan added: “But that is our great system at work. And I am proud of what we have achieved together to make this a stronger and more prosperous country.”

Ryan’s speech caps off a career that saw him rise from a budget-minded congressman to Mitt Romney’s vice presidential pick in 2012 to the House speaker. He ends his time in Congress after a difficult two years dominated by the unpredictable decision-making and hardball politics of President Trump, whose coarse leadership style and comments occasionally prompted from the affable Midwestern lawmaker a gentle rebuke. He also struggled to deal with gridlock on Capitol Hill, including Republican divisions over issues including health care and immigration.

“The state of politics these days is another question, and frankly one I don’t have an answer for,” Ryan said. “As I look ahead to the future, this much I know: Our complex problems are solvable. That is to say, our problems are solvable if our politics will allow it.”

Ryan's departure also comes six weeks after an Election Day that saw Democrats capture House control. Their triumph followed a campaign in which they battered Republicans for trying to repeal and replace former President Barack Obama's health care law, a primary GOP priority, and for their alliance with Trump.

“The House will become the care of a new majority, and what I know will be a spirited Republican minority. I wish our next leaders well,” he said. “It is precisely because all of this is so momentary … it is because you are just a small part of history, that you are inspired to do big things. On this score, we have achieved a great deal.”

Under Ryan, Congress approved the biggest tax cuts in decades, boosted defense spending and rolled back Obama regulations protecting clean air and water. But annual federal deficits are surging, Medicare and other expensive entitlement programs are growing and their attempt to scuttle Obama's health care statute crashed.

The 48-year-old Ryan acknowledges he never achieved two longtime policy dreams — reining in spending by the government's huge entitlement programs and controlling the enormous and growing national debt. Thanks partly to the 10-year, $1.5 trillion tax cut Republicans enacted last year, the nonpartisan Congressional Budget Office estimates a record $12.4 trillion accumulated federal deficits for the coming decade.

"I acknowledge plainly that my ambitions for entitlement reform have outpaced the political reality and I consider this our greatest unfinished business," he said.

While the House-passed health care bill would have culled savings from Medicaid and other programs, the effort died in the GOP-run Senate, killed by solid Democratic opposition and a handful of Republican opponents.

"Ultimately, solving this problem will require a greater degree of political will than exists today. I regret that," Ryan said.

Ryan was first elected to Congress in 1998 and became a leader of Republicans trying to shrink government. As chairman of the House Budget Committee, he wrote spending plans that envisioned squeezing savings from popular benefit programs like Medicare and eliminating deficits — proposals that Congress never actually enacted.

He was Mitt Romney's vice presidential running mate in 2012, and he became speaker in 2015 after conservative unrest prompted the abrupt resignation of his predecessor, Rep. John Boehner, R-Ohio. Ryan announced last April that he would not seek re-election to the House, citing a desire to spend more time with his family.

While Ryan did not specifically mention Trump in his speech, he denounced the sort of divisiveness that Trump has been accused of encouraging. Ryan, however, had sharp words for politicians on both sides of the aisle, and called out the bickering and personal shots taken in the media and social media.

“Genuine disagreement tends to give way to intense mistrust,” he said. “Being against something has more currency than being for something.”

He added: "All of this pulls on the threads of our common humanity, in what could be our unraveling.”

He suggested that "rediscovering that human connection is one lane on the road back to aspiration and inclusion as the guiding influences in public life." He added, "The drivers of our broken politics are more obvious than the solutions."

On immigration, Ryan said no matter how the current border wall battle is resolved, "The system will still be in need of serious reform. And no less than our full potential as a nation is at stake."

Ryan for years was a quiet force for broad immigration overhauls that conservatives opposed as going too far in offering citizenship to immigrants in the U.S. illegally, but as speaker couldn't unify Republicans behind one approach.

The Associated Press contributed to this report.