Erie County wants two mortgage giants that back most home loans to pay real estate transfer taxes, and it’s taking them to court in an attempt to recoup the money.

The county Wednesday filed a federal lawsuit against Freddie Mac and Fannie Mae that asks the court to determine that the government-chartered corporations are not exempt from paying the tax on thousands of mortgages they handle in Erie County. The lawsuit seeks to recoup more than $2 million in unpaid transfer taxes, as well as interest and penalties.

“They’re publicly traded companies,” said Edward L. Smith III, an attorney with the law firm Cantor, Dolce & Panepinto, which filed the lawsuit on behalf of the county. “Their stock is traded on the stock exchanges. They have officers who are certainly paid high salaries, and they have shareholders just like any other private corporation would. So it’s our position they are a private corporation and responsible to pay a transfer tax just as any other individual and private corporation would.”

Freddie Mac and Fannie Mae have received exemptions from the tax under state law that spares government agencies from paying it.

The county’s lawsuit follows similar claims filed by other counties throughout the United States. Last year, a federal court in Michigan rejected arguments made by Freddie Mac, Fannie Mae and the Federal Housing Finance Agency that they were exempt from real estate transfer taxes. The decision has been appealed.

“It is a matter of fundamental fairness,” County Executive Mark C. Poloncarz said in a statement regarding the lawsuit. “Two of the largest companies in the world should pay their taxes just like you and I do.”

Andrew Wilson, a spokesman for Fannie Mae, said he could not comment on pending litigation. A spokesman for Freddie Mac did not return a call to comment.

Cantor, Dolce & Panepinto proposed filing the lawsuit on behalf of Erie County in conjunction with another potential claim the firm is investigating involving the way the Mortgage Electronic Registration Systems Inc. and national lenders filed documents with the Erie County Clerk’s Office, said County Attorney Michael Siragusa.

The firm is working on a contingency fee in both cases, Siragusa said, and the county will pay nothing for either lawsuit unless it receives an award.

“We approached the county,” said Marc Panepinto, a partner with Cantor, Dolce & Panepinto. “We think Fannie and Freddie are avoiding the excise tax. We think the county can recover money.”

Panepinto said the firm anticipates filing a lawsuit on behalf of Erie County later involving the way Mortgage Electronic Registration Systems and the lending industry filed records in the Erie County Clerk’s Office and is investigating whether the county has a claim related to robo-signing or other mortgage practices used by the banking industry.

Smith said the firm is investigating several areas, including whether or not there were proper assignments and discharges of mortgages and whether or not documents filed were accurate and signed by the right people.

Panepinto, who last year briefly sought the chairmanship of the Erie County Democratic Party, has been a frequent donor to political candidates in Erie County, including Poloncarz.