Richard Cordray, the embattled head of the Consumer Financial Protection Bureau, said Wednesday he will step down before the end of the month.

Cordray had been under fire from congressional Republicans almost from the time he took over the bureau, which emanated from the Dodd-Frank reforms following the financial crisis.

He announced the resignation in an email to employees.

"As I have said many times, but feel just as much today as I ever have, it has been a joy of my life to have the opportunity to serve our country as the first director of the Consumer Bureau by working alongside all of you here," he wrote.

His departure was not unexpected. Sources earlier this month told CNBC that President Donald Trump was ready to sack Cordray but was afraid of turning him into a Democratic hero.

The White House's reaction to Cordray's departure was reserved.

"The administration will announce an acting director and the president's choice to replace Mr. Cordray at the appropriate time," Raj Shah, deputy press secretary, said in a statement.

In addition to the political fire in Washington, Cordray has long been speculated as a potential candidate for Ohio governor. He made no mention of his plans in the email.

The CFPB has been a sore spot among GOP leaders who view the bureau as the poster child for postcrisis regulatory overreach.

On the other hand, Rep. Maxine Waters (D-California) praised Cordray for "standing up to abusive financial institutions."

"Richard Cordray is a true champion for American consumers. Under his outstanding leadership, the Consumer Bureau has made the financial marketplace stronger and fairer for hardworking Americans across the country," Waters said in a statement.

Former FDIC Chair Sheila Bair said Cordray's biggest accomplishments will be i reshaping mortgage lending standards, stronger enforcement and a greater watchdog presence over big Wall Street banks.

"None of that consumer focus was really present in our bank regulatory system prior to the CFPB's creation," Bair said on CNBC's "Power Lunch."

The full text of Cordray's message to employees:

Dear Colleagues,

I wanted to share with each of you directly what I have told the senior leadership in the past few days, which is that I expect to step down from my position here before the end of the month.

As I have said many times, but feel just as much today as I ever have, it has been a joy of my life to have the opportunity to serve our country as the first director of the Consumer Bureau by working alongside all of you here. Together we have made a real and lasting difference that has improved people's lives, notably: $12 billion in relief recovered for nearly 30 million consumers; stronger safeguards against irresponsible mortgage practices that caused the financial crisis and hurt millions of Americans; giving people a voice by handling over 1.3 million complaints that led to problems getting fixed for vast numbers of individuals, and creating new ways to bring financial education to the public so that people can take more control over their economic lives. None of this could have happened without all of us being dedicated to pull together in supporting and protecting people and making every consumer count. I will always be immensely proud of you and what you have done.

At the same time, there is always more work that lies ahead. That would be true at any point, of course, and one thing I have tried to reinforce this year is that the Consumer Bureau is far more than its director. I am confident that you will continue to move forward, nurture this institution we have built together, and maintain its essential value to the American public. And I trust that new leadership will see that value also and work to preserve it – perhaps in different ways than before, but desiring, as I have done, to serve in ways that benefit and strengthen our economy and our country.

My gratitude and appreciation for what you mean to me and to our nation is deep and lasting, and I will be taking the opportunity to make that clear to you in person over the days ahead.

Thank you!

RC

—With reporting by CNBC's Michelle Fox.