In 2009, as the financial crisis raged and General Motors and Chrysler plunged toward bankruptcy, Tesla Motors faced a seemingly impossible task: raising half a billion dollars to build an electric-car factory. Tesla had just staggered through a year of layoffs, canceled orders, and record losses. Then suddenly, salvation. The U.S. Department of Energy offered to lend the company $465 million at rock-bottom interest rates.

Four years later, Tesla Motors offers a remarkable example of how a well-timed government investment in the right company can pay off. Every week, 400 all-electric Model S sedans roll out of Tesla’s factory in Fremont, Calif., which the government’s loan financed. Motor Trend named the Model S its 2013 Car of the Year. Tesla’s stock is the toast of Wall Street, giving the company a market value topping $12 billion. And in sharp contrast to Solyndra, the solar panel maker that defaulted on its $528 million loan from the Energy Departtment, Tesla last week paid the government back early, with interest.

Yet despite all the public celebration, both Solyndra and Tesla stand as warnings of the dangers in deputizing bureaucrats to play bankers and venture capitalists. In both loans, the government walked away laughably undercompensated for the risk it accepted in the startup companies. In fact, the Tesla deal was arguably far more costly for America than the Solyndra fiasco.

Solyndra exposed the first way the taxpayer could lose out. The traditional advantage of making a loan (as opposed to buying stock in a company) is that lenders often get paid something even when the borrowing company fails, because they hold collateral. Solyndra’s bankruptcy revealed the ephemeral value of the government’s collateral. Taxpayers have yet to recover a penny from the company.

Tesla’s runaway success, by contrast, is demonstrating how making venture capital–style investments in risky companies—without demanding venture capital–style compensation in return—can end up costing taxpayers even more. In Silicon Valley, one Google pays for a dozen Pets.com. The government made the key mistake of loaning money to Tesla without insisting on receiving stock options, options that could have allowed the Department of Energy to pay for the Solyndra losses several times over.

When the government’s negotiators started hammering out the details of the Tesla investment in mid-2009, it was obvious to both sides that the feds were in a position to name their terms. Tesla’s management knew that if they couldn’t get the government’s money at 3 or 4 percent interest, their next cheapest source of capital would cost 10 times more, a whopping 30 to 40 percent annually. (That’s according to estimates Tesla made in a regulatory filing, which based its numbers on “venture capital rates of return for companies at a similar stage of development as us.”)

Today, the Energy Department defends the massive discount it offered as perfectly appropriate. “The loan program wasn’t intended to generate profit; the goal of the program is to provide affordable financing so that America’s entrepreneurs and innovators can build a strong, thriving and growing clean energy industry in the United States,” says a department spokeswoman.

Yet isn’t affordability the exact reason stock options are standard in normal venture capital deals? When a company is struggling, the options can’t be exercised and thus are perfectly affordable, not draining a dollar of cash from a startup company. Unlike a loan, stock options only cost the company money if it goes on to success—at which point it can afford to share that success with its early investors.

Personal loans made in 2008 by Elon Musk, Tesla’s co-founder and CEO, provide a telling contrast. Musk received a much higher interest rate (10 percent) from Tesla and, more importantly, the option to convert his $38 million of debt into shares of Tesla stock. That’s exactly what he ended up doing, and the resulting shares are now worth a whopping $1.4 billion—a 3,500 percent return on his investment. By contrast, the Department of Energy earned only $12 million in interest on its $465 million loan—a 2.6 percent return.

The government had huge leeway to demand similar terms as part of its loan, given the yawning gap between its interest rate and the cost of Tesla’s next-best source of capital. The government was ponying up more capital than all of Tesla’s previous investors combined. At a bare minimum, the Department of Energy could have demanded a share of the company equal to the 11 percent Musk received for his $38 million loan the year before. Such an 11 percent share would be worth $1.4 billion to taxpayers today.

And if the government had wanted to bargain like a real venture capitalist, Tesla’s desperate need for cash gave the feds the power to demand options on half the company’s stock, or more. Over at the Treasury Department, negotiators were demanding big ownership stakes in exchange for life-saving bailouts. The Treasury wound up owning 85 percent of AIG’s stock and 32 percent of GM’s.

There was nothing to prevent DOE from demanding stock options from Tesla. Tesla’s loan came courtesy of a 2007 law signed by George W. Bush, which provided $25 billion for loans backing “Advanced Technology Vehicles Manufacturing.” While Congress required the Energy Department to lend at low rates, equal to what the government pays, the law was silent on the issue of stock options.

And, in fact, the Energy Department actually did negotiate for options on 3 million shares of Tesla stock as part of the original loan, options that would be worth $300 million based on Tesla’s current share price. Unfortunately for taxpayers, those options no longer exist. Tesla had the right to force the extinguishment of those options by repaying the loan early, as it just did. (The Energy Department says that was expected, since unlike typical options these were never meant to turn a profit but rather to encourage Tesla to repay the loan early if it could.)

Elon Musk didn’t mention that $300 million reason when he explained last week why Tesla was repaying the loan early. Musk cast the repayment not as a responsibility to his shareholders but rather as a moral duty to the taxpayers who made his company’s success possible. “Having accepted taxpayer money, I thought we had an obligation to repay it as soon as we reasonably could,” Musk told the Wall Street Journal last week.

Asked to explain what, in fact, was Musk’s primary motive for the loan repayment, a Tesla spokesperson declined to comment. (Musk also told the Journal that “If economics were the only consideration we would not have done this,” despite the company’s significant economic incentive to kill the government’s options.)

Supporters of the government stimulus program point to Tesla as a shining example of how such investments can be long-term successes. “Ultimately, making the U.S. the leader in advanced vehicles and clean energy will pay for itself many times over as our economy grows and new industries are created,” says an Energy Department press officer.

Here’s hoping that proves true. In the meantime, the question of how to compensate taxpayers for Tesla-esque successes remains a distinct issue, one that the government would do well to pay more attention to the next time it plays venture capitalist. If the government had demanded an ownership stake in reasonable proportion to the amount of money it put at risk, Tesla would be just as successful as it is today. The only difference would be that the taxpayers who saved the company would share in that success.