When I started Citizens Energy Corp. in 1979, the goal was to create an oil company that would help the poor.

Tax lawyers said we should become a nonprofit 501(c)(4). As a company providing heating oil to the needy, we would qualify as a “social welfare organization” and therefore be exempt from federal income taxes — allowing us to give away even more to the poor.

Unlike nonprofit 501(c)(3) charities, which collect tax-deductible contributions, 501(c)(4)s generate most of their revenues from dues and fees and business activities. Thousands of organizations work the same way, channeling funds into providing a concrete social benefit to the public.

But recent revelations about political groups abusing their tax-exempt status show how far nonprofits have been allowed to stray from the mission of serving the public.

While legitimate 501(c)(4)s spend over $40 billion annually on social welfare projects, others — ranging from Karl Rove’s Crossroads GPS to the Democratic-leaning Priorities USA — collect hundreds of millions of dollars in secret contributions to spend on political campaigns.

Most of the dark money funneling through 501(c)(4)s supports Republican candidates. In 2012, over 80 percent of more than $300 million in such spending was plunked down by conservative groups. Yet many of these groups checked the “no” box when asked by the IRS whether they planned to engage in any campaign activity. The Koch brothers’ Americans for Prosperity spent a whopping $39.4 million to defeat Democrats in 2010, despite claiming they would spend nothing on elections.

It is ludicrous to think that such spending is a legitimate expression of a “social welfare organization.” No one should be able to spend tax-free dollars — or be able to deduct donations as a business expense — to elect candidates.

The 1913 enabling legislation of the nonprofit section of the tax code provided the exemption to groups “operated exclusively for the promotion of social welfare.” However, for complex reasons, a 1959 regulation declared that “exclusively” meant “primarily.”

For the next 40 years, 501(c)(4)s provided a vehicle for nonprofits to spend tax-exempt dollars on advocacy efforts. In the meantime, federal regulators used the “primarily” interpretation to rule that groups could keep their 501(c)(4) status so long as no more than 49 percent of their spending went toward politics.

Then came two key Supreme Court rulings: The 2010 Citizens United case allowed unlimited corporate money to be spent on politics; and a separate decision that accepted the argument that ads targeting US Senator Russell Feingold of Wisconsin were not political because they did not tell the public how to vote.

Suddenly, political 501(c)(4)s sprang up like mushrooms. Political mercenaries took advantage of the loophole, arguing that their 501(c)(4) political ads, financed with hidden money, served the public welfare by educating the public.

The result is that they routinely engage in a clear conflict of interest by using their tax-exempt status — a benefit conferred by the American people — to operate as super PACs, spending millions of corporate dollars to influence who runs the government.

A number of solutions have been proposed to end the abuse, ranging from executive orders and legal challenges to regulatory proposals and legislation. None has yet succeeded in cleaning up the mess. From Tea Party groups to Organizing for America — which morphed out of President Obama’s campaign — political 501(c)(4)s continue to grow.

Meanwhile, the IRS continues to reel under revelations that it improperly ordered investigations of groups with the words “Tea Party,” “Israel,” “progressive,” and “occupy” in their titles.

Legislation is the best guarantor that the IRS close the 501(c)(4) loophole. By returning to the “exclusive” standard that prevailed before 1959, any spending outside of that serving the social welfare would be banned. Such legislation should also codify once and for all clear standards for determining when advocacy communication crosses the line from public education to partisan purpose. However, the political divide on Capitol Hill makes the odds of passing any such bill highly unlikely.

The IRS and the Treasury recently agreed to consider regulatory reform. The IRS should at least:

■ Require that political contributions of $250 or more to 501(c)(4)s be publicly reported, pulling away the mantle of secrecy that cloaks all donors.

■ Deny companies the ability to write off as business expenses any donations made to political 501(c)(4)s.

■ Codify regulatory standards for what constitutes political speech.

Section 501(c)(4) of the tax code provides a legitimate financial advantage to organizations devoted to social welfare. But its benefits should not be extended to political posers and pretenders hiding secret donations beneath a nonprofit disguise.

Joseph P. Kennedy II, a former US congressman, is chairman, president, and founder of Citizens Energy Corp.