Apple (Nasdaq: AAPL) Chief Executive Officer Tim Cook defended his company’s use of offshore tax shelters before U.S. senators who castigated the most-valuable technology company for avoiding $9 billion and more in payments.

“We pay all the taxes we owe — every single dollar,” Cook said in testimony today to the Senate Permanent Subcommittee on Investigations. “We not only comply with the laws, we comply with the spirit of the laws.”

Senator Carl Levin used the hearing to say Apple used “loopholes” to avoid paying $9 billion in U.S. taxes in 2012.

“Apple executives want the public to focus on the U.S. taxes the company has paid, but the real issue is the billions in taxes it has not paid,” said Levin, a Michigan Democrat. Apple employs “offshore tax strategies whose purpose is tax avoidance, pure and simple,” he said.

Today’s hearing was called to air accusations the iPhone maker has created a web of offshore entities to avoid paying U.S. taxes.

Apple, in written testimony, denied any wrongdoing and said the company was one of the largest taxpayers in the U.S., having paid $6 billion last year. Cook called for a simplified U.S. corporate tax code that would allow capital to flow back to the U.S., “fully recognizing that this would likely result in an increase in Apple’s U.S. taxes.”

He told lawmakers that he didn’t feel pressured to testify. “I think it’s important to tell our story,” Cook said.

Senate Dissent

In the last four years, Apple has avoided paying taxes on $44 billion in income, said Senator John McCain of Arizona, the panel’s top Republican. He called the company “one of the biggest tax avoiders in America.”

Three entities set up in Ireland hold 60 percent of Apple’s profits and claim to be tax residents “nowhere in the world,” McCain said. “It’s completely outrageous.”

Not all lawmakers supported summoning Apple executives to the hearing. Senator Rand Paul, a Kentucky Republican, said Apple was dealing with an “awful” tax code.

“I’m offended by the spectacle of dragging in executives from a company that is not doing anything illegal,” Paul said. “I frankly think the committee should apologize to Apple.”

Levin said there would be no apology. “Apple’s a good company but no company, no company should be able to determine how much it’s going to pay in taxes,” Levin said.

Company Response

Cook and two other executives — including Chief Financial Officer Peter Oppenheimer — appeared before the subcommittee. The panel, led by Levin, in a report yesterday said Apple’s subsidiaries include three entities that have no home country for tax purposes.

Apple said its cash is largely held in U.S. banks in dollar-denominated assets, segregated into a portion that can be used for domestic operations and a portion that can be used only for international investments, the company said. The company doesn’t use foreign subsidiaries or gimmicks to avoid U.S. taxes, said the testimony.

The company also said the Irish subsidiaries, which are cost-sharing arrangements, have helped fund Apple’s research and development activities and taken on risks, leading to bigger profits and higher-paying jobs in the U.S.

Apple shares were down $1.57 or 0.4 percent, to $441.36, at 12:12 p.m. New York time.

Microsoft, Hewlett-Packard

The Senate committee has been examining companies that use various maneuvers to reduce their tax bills, in addition to Apple including Microsoft Corp. and Hewlett-Packard Co.

Some of the largest U.S.-based companies — including those in technology, energy and pharmaceutical industries — expanded their untaxed offshore stockpiles by $183 billion in the past year, increasing such holdings by 14.4 percent, according to data compiled by Bloomberg.

Microsoft , Apple and Google Inc. each added to their non- U.S. holdings by more than 34 percent as they expanded on prior tax maneuvers to earn and park profits in low-tax countries. The build-up of offshore profits — totaling $1.46 trillion for the 83 companies examined — has increased because of incentives in the U.S. tax code for booking profits offshore and leaving them there. This has complicated attempts by Congress to overhaul the corporate tax system.

Apple has said in filings with the U.S. Securities and Exchange Commission that it has $40.4 billion in earnings outside the U.S. on which it hasn’t paid U.S. taxes. If Apple brought that money back to the U.S., the company would owe $13.8 billion, according to the filings.

‘Case Study’

The panel’s report is designed to be a “case study” of how a company is able to pay an effective tax rate much lower than the 35 percent U.S. corporate rate, according to staff members on the subcommittee.

The bipartisan probe found Apple, through cost-sharing arrangements, has transferred offshore the profits powered by economic rights to its patents and other intellectual property – – aspects like licensing and sales. At the same time, the legal rights to its patents remain in the U.S., the panel found.

Apple’s relationship with the offshore affiliates isn’t arms’ length, the probe found. Apple has $102 billion in offshore accounts and shifted billions in profits out of the U.S. into affiliates based in Ireland, where it negotiated a tax rate of less than 2 percent, according to a report by the panel. Levin today labeled them “ghost companies.”

Offshore Entities

The offshore entities of the Cupertino, California-based company have paid little or no tax in recent years, the congressional report said.

One affiliate — Apple Operations International –generated net income of $30 billion between 2009 and 2012. It declined to declare a tax residence, filed no corporate tax return and paid no income taxes to any nation, the report said. AOI is Apple’s principal offshore holding company.

One of the Irish entities, Apple Sales International, before 2012 had no employees, and two of its three directors are Apple Inc. employees located at its California headquarters. All 33 ASI board meetings between May 2006 and March 2012 took place in Cupertino, the report found.

ASI buys Apple’s finished products from a Chinese manufacturer, resells them at a higher price to Apple affiliates and retains the profits, the report said.

Apple has a low tax rate on products it sells outside the U.S., Cook said. “There’s no shifting going on that I see, at all,” he said.

Lawmakers in both parties are seeking a bipartisan agreement on how to tax income that U.S.-based corporations earn outside the country. Democrats and Republicans on the panel say Apple’s tax maneuverings, while not illegal, will help frame debate about how to make corporate taxes more fair.

McCain said he and Levin are seeking to craft a bipartisan proposal that would end some of the tax benefits, although the timing of an agreement isn’t clear. He said both parties in Congress should seek to address the matter, even if it isn’t in the context of a broad rewrite of the tax code.

“When you see egregious behavior like this, why wait?” McCain said.