WASHINGTON – Apple Chief Executive Officer Tim Cook Tuesday 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 Tuesday to the Senate Permanent Subcommittee on Investigations. “We not only comply with the laws, we comply with the spirit of the laws.”

Sen. Carl Levin used the hearing to say Cupertino, Calif.-based 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, D-Mich. Apple employs “offshore tax strategies whose purpose is tax avoidance, pure and simple,” he said.

Tuesday’s hearing was called to air accusations the iPhone, iPad and iPod maker has created a web of offshore entities to avoid paying U.S. taxes. Other large U.S. companies also keep profits offshore but Apple was the focus of the Senate probe.

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 United States, “fully recognizing that this would likely result in an increase in Apple’s U.S. taxes.”

In almost two hours of testimony, Cook sat before television cameras and fielded questions from senators, at times sparring with them.

“You point out, and accurately so, Mr. Cook, that 95 percent of the creativity that goes into those products is in California,” Levin said. “But two-thirds of the profits, in Ireland.”

“Senator, we’re proud that all of our R&D, or the vast majority, is in the United States,” Cook said.

“I know, but the profits that result from it are sitting in Ireland in corporations that you control that don’t pay taxes,” Levin said. “You ought to be proud!”

Cook left the hearing surrounded by an entourage and reporters, and offered no comment aside from a thumbs-up sign when asked if he had a chance to make his case.

Earlier, Cook called the tax issue “a very complex topic.” “I’m glad that we’re having the discussion,” Cook said. “Honestly speaking, I don’t see it as being unfair. I’m not an unfair person. That’s not who we are as a company.”

In the last four years, Apple has avoided paying taxes on $44 billion in income, said Sen. 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. Sen. Rand Paul, R-Ky., 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.

Paul called Apple “a great American company” and said it had sought to minimize its tax burden legally. “It would probably be malpractice for them not to do so,” Paul said.

White House Press Secretary Jay Carney said Levin and McCain did an “important” job raising questions about companies that “shift profits and their jobs offshore.”

President Barack Obama “has long argued that the tax code is tilted against companies that want to create jobs in America while it rewards companies for shipping jobs and profits overseas,” Carney said Tuesday.

Obama wants to make sure that companies “cannot use offshore profit-shifting to avoid paying taxes,” including levying a minimum tax on foreign earnings, he said.

The administration wants to work with Levin and McCain to overhaul the tax code, Carney said.

Cook and two other executives — including Chief Financial Officer Peter Oppenheimer — appeared before the subcommittee.