Updated

President Barack Obama on Monday gave employment protection to gay and transgender workers in the federal government and its contracting agencies, after being convinced by advocates of what he called the "irrefutable rightness of your cause."

"America's federal contracts should not subsidize discrimination against the American people," Obama said at a signing ceremony from the White House East Room. He said it is unacceptable that being gay is still a firing offense in most places in the United States.

The fight over a gay discrimination ban for private employers has become embroiled in a dispute over whether religious groups should get an exemption.

Until last month, Obama long resisted pressure to pursue an executive anti-discrimination order covering federal contractors in the hope that Congress would take more sweeping action banning anti-LGBT workplace discrimination across America. A bill to accomplish that goal -- the Employment Non-Discrimination Act -- passed the Senate last year with some Republican support, but has not been taken up by the GOP-controlled House. "We're here to do what we can to make it right," Obama said.

Some prominent gay-rights and civil-rights organizations which had been longtime supporters of that bill announced earlier this month that they were withdrawing their support because of a broad religious exemption included to attract Republican votes.

Since Obama announced that he would take executive action, he's faced pressure from opposing flanks over whether he would include an exemption for religious organizations. He decided to maintain a provision that allows religious groups with federal contracts to hire and fire based upon religious identity, but not give them any exception to consider sexual orientation or gender identity. Churches also are able to hire ministers as they see fit.

Obama's action comes on the heels of the U.S. Supreme Court's recent ruling in the Hobby Lobby case that allowed some religiously oriented businesses to opt out of the federal health care law's requirement that contraception coverage be provided to workers at no extra charge. Obama advisers said that ruling has no impact on non-discrimination policies in federal hiring and contracting.

Obama said 18 states and more than 200 local governments already ban employment discrimination based on sexual orientation, as well as a majority of Fortune 500 companies. But he noted that more states allow same-sex marriage than prohibit gay discrimination in hiring.

"It's not just about doing the right thing, it's also about attracting and retaining the best talent," Obama said.

The change for federal contracting will impact some 24,000 companies with 28 million workers, or one-fifth of the U.S. workforce. Many large federal contractors already have employment policies barring anti-gay workplace discrimination. However, the Williams Institute at UCLA Law School estimates that the executive order would extend protections to about 14 million workers whose employers or states currently do not have such nondiscrimination policies.

While few religious organizations are among the biggest federal contractors, they do provide some valued services, including overseas relief and development programs and re-entry programs for inmates leaving federal prisons.

Obama's signature amended two executive orders. The first, signed by President Lyndon Johnson in 1965, prohibits federal contractors from discriminating based on race, religion, gender or nationality in hiring. President George W. Bush had amended Johnson's order in 2002 to add the exemption for religious groups.

Obama added sexual orientation and gender identity to the list of protections, and ordered the Labor Department to carry out the order. Administration officials said that means the change will probably take effect by early next year.

Obama also amended an order signed by President Richard Nixon in 1969 to prevent discrimination against federal workers based on race, religion, gender, nationality, age or disability. President Bill Clinton added sexual orientation, and Obama will include gender identity in a change that will immediately take effect.