Richard Cordray, a target of the banking industry and Republicans in Congress, announced on Wednesday that he would step down as head of the Consumer Financial Protection Bureau by the end of the month.

Cordray's resignation gives President Donald Trump a significant opportunity to reshape an agency that oversees a significant portion of the financial industry. It comes less than a month after the agency suffered a stunning defeat when Congress voted to block one of its most aggressive regulations allowing consumers to sue their banks.

"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," Cordray said in a message 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."

The bureau, known as the CFPB, was one of the central achievements of the Obama administration following the 2008 financial crisis. It regulates the way banks and other financial companies interact with consumers, policing everything from pay day loans to mortgages. Since its creation, it has extracted billions in fines from big banks, including $100 million from Wells Fargo last year for opening millions of sham accounts that customers didn't ask for.

But the agency has been controversial among Republicans since its inception. The CFPB has made it more difficult for people to get a mortgage loan and overstepped its power to regulate some industries, including auto loans, critics say.

Cordray has been mulling a run for governor of Ohio where he once served as attorney general.