WASHINGTON — As a freshman senator with his eye on the presidency, Barack Obama said he'd never shop at a Wal-Mart and held the company up as an emblem of corporate greed.

Today, Wal-Mart Stores Inc. is one of Obama's most reliable corporate allies, a go-to partner that's backed the White House on more than a dozen business initiatives, particularly Obamacare and climate change.

The pairing benefits both. Obama can point to Wal-Mart's support to beat back Republican charges that he's hostile to business. Wal-Mart can point to the president's embrace to lure squeamish shoppers who, like Obama of old, have stayed away out of a belief the company hurts workers and undercuts competition. This is a key part of the company's effort to spur continued growth.

"It only makes sense for the president to be willing to strike a partnership with the nation's largest retailer," said Dwight Hill, a Plano, Texas-based partner with retail consultancy McMillan Doolittle. "And Wal-Mart has made more strides of late to try to be more transparent about worker pay and benefits. They have certainly seen the light."

The president completed the turn from Wal-Mart antagonist to fan when he visited one of the retailer's stores in Mountain View, Calif., in 2014 to praise its use of renewable energy. Obama's visit represented a "major milestone" for the company and its public image, said Jib Ellison, whose consulting firm worked on Wal-Mart's sustainability program.

"When he got elected, his rhetoric was very anti-Wal-Mart," said Ellison, who continues to advise Wal-Mart on environmental policies. "So it's reaffirming."

The partnership between the president and the retailer is especially strong in two areas: health care and climate change.

Obama's view of Wal-Mart shifted early in his presidency when he realized he needed business support to advance his health care overhaul, which Republicans claimed would kill jobs and drive companies out of business. Wal-Mart was one of the first major employers to sign on to the plan. In June 2009, as debate raged in Congress, Wal-Mart publicly released a letter to Obama saying it supported requiring employers to offer health insurance to their workers, a keystone of the law.

For Wal-Mart, the Affordable Care Act resolved a major gripe about the company: that it provided weak health benefits for its more than 1 million workers in the U.S. Obamacare created a system of subsidized insurance for middle-income Americans and expanded the Medicaid program for the poor to cover people earning poverty-level wages. Pressure subsided on Wal-Mart to provide coverage. When government-run insurance exchanges opened in 2014, Wal-Mart stopped offering health insurance to 30,000 part-time workers.

"Obamacare is great for Wal-Mart workers; it was a huge transfer of wealth," said Nelson Lichtenstein, director of the Center for the Study of Work, Labor, and Democracy at the University of California, Santa Barbara, who wrote a book on Wal-Mart. "The pressure is off Wal-Mart to provide better health insurance to its own employees. If you're a single mom and work at Wal-Mart you now qualify for Medicaid."

Wal-Mart and the White House have cooperated on Obama's climate agenda, which current and former company executives described as a natural gelling of interests rather than a political calculation. Wal-Mart began pushing to cut its carbon footprint in 2005 as a way to not only help the environment, but also improve its public image, and is now the largest corporate user of solar energy.

Last year, the company endorsed the global accord Obama negotiated in Paris to reduce carbon emissions.

Leslie Dach, who ran Wal-Mart's government relations and corporate affairs department from 2006 until 2013 before joining the Obama administration, published a piece in the Huffington Post shortly before leaving the company titled: "Wal-Mart Agrees With the President: The Time for Renewables Has Come." The retailer seized upon an offhand comment by the president during a speech that week at Georgetown University, in which he said "Wal-Mart deserves a cheer" for reducing carbon pollution.

Obama's senior adviser Valerie Jarrett said the White House has found in Wal-Mart a willing partner as it reached out to various businesses to embrace administration's initiatives.

"We recognize that the private sector is the economic engine of our country," Jarrett said in an interview. "It's not enough just to have these policies on the books."

Working with the administration helps the retailer address the social and environmental issues that the company's customers care about, said Kathleen McLaughlin, Wal-Mart's chief sustainability officer and CEO of the Wal-Mart Foundation.

"It's so essential that we have these collaborations," she said.

When Wal-Mart announced it would raise its minimum wage for employees in early 2015, after some encouragement from the administration, Obama called Wal-Mart Chief Executive Officer Doug McMillon from Air Force One to congratulate him and told a crowd in North Carolina that "once Wal-Mart is paying people more, then you know that something is happening, right?"

The pair have also worked on veteran employment, financial security, workforce training, gun control, criminal justice issues and first lady Michelle Obama's healthy lifestyle campaign. As Obama was urging Congress to pass tougher restrictions on guns, Wal-Mart removed military-style rifles from its stores in August 2015, citing declining demand.

For Wal-Mart, all of this is aimed at bolstering its standing with a key demographic of shoppers it must reach for continued growth — upper-income families in traditionally liberal areas like Chicago, Los Angeles and the East Coast.

"Given the fact the company isn't growing that much, they really need to expand, in these coastal cities," Lichtenstein said. "There has been a certain percentage of Americans that just won't shop there for political reasons."

The company's warm ties with Obama don't seem to bother its base of customers in redder parts of the country. In Elizabeth, Colo., a fast-growing area about 46 miles southeast of downtown Denver where just 13 percent of voters identify themselves as Democrats, some shoppers recoiled at a reporter's mention of Obama's name. Others said they didn't care.

Betty Erickson, 82, a retired cashier, said she cares more about whether Wal-Mart's shelves are fully stocked and their prices stable than the company's decision to discontinue selling rifles or other politically controversial products.

"But I am glad that they are paying their workers more," she said.

Money has followed Wal-Mart's embrace of Obama. The company increased its political spending during his presidency, with donations to Democrats no longer trailing Republicans by huge margins.

Wal-Mart's political action committee gave $1.2 million to federal candidates during the 2012 cycle, according to the Center for Responsive Politics, a Washington nonprofit that tracks campaign spending. Democrats claimed about half that money, up from 21 percent in 2004 and only 14 percent in 2000. So far this cycle, Democrats have received about 41 percent of Wal-Mart's $1.1 million in contributions, with Republicans getting the rest.

Alice Walton, the daughter of Wal-Mart founder Sam Walton, gave $353,000 to Hillary Clinton's joint fundraising committee with the Democratic National Committee.

The detente, however, does not include some Democrats who continue to criticize Wal-Mart — as Obama once did — for its labor practices and relatively low wages. The retailer is still a favorite target for attacks by party activists. Vermont Sen. Bernie Sanders continues to hold the company up as the epitome of inequality and has said it should "get off of welfare, pay your workers a living wage."

Wal-Mart still has work to do before coastal liberals brave its Supercenters, said Allen Adamson, founder of BrandSimple Consulting, and it will likely have to continue to cozy up with Democrats to sway opinions.

"They are starting to make some progress, but it is very hard if you are very big to change people's perceptions," Adamson said. "Once consumers categorize you as big, but not necessarily good, it is hard to change that perception."