Unknown hackers infected the computers of some Apple workers when they visited a website for software developers that had been infected with malicious software.
The malware had been designed to attack Mac computers, the company said in a statement.
The same software, which infected Macs by exploiting a flaw in a version of Oracle Corp's Java software, was used to launch attacks against Facebook (NasdaqGS: FB - news) , which the social network disclosed on Friday.
The malware was also employed in attacks against Mac computers used by "other companies", Apple said, without elaborating on the scale of the assault.
But a person briefed on the investigation into the attacks said hundreds of companies, including defence contractors, had been infected with the same malicious software, or malware.
The attacks mark the highest-profile cyber attacks to date on businesses running Mac computers.
Hackers have traditionally focused on attacking machines running the Windows operating system, though they have gradually turned their attention to Apple products over the past couple of years.
"This is the first really big attack on Macs," the source told Reuters.
"Apple has more on its hands than the attack on itself."
Cyber-security attacks have been on the rise.
In last week's State of the Union address, US President Barack Obama issued an executive order seeking better protection of the country's critical infrastructure from cyber attacks.
Over the weekend, cyber-security specialists Mandiant reported that a secretive Chinese military unit was believed to have orchestrated a series of attacks on US companies, which Beijing has strongly denied.
There was no indication as to whether the group described by Mandiant was involved in the attacks described by Apple and Facebook.
An Apple spokesman declined to specify how many companies had been breached in the campaign targeting Macs, saying he could not elaborate further on the statement it provided.
"Apple has identified malware which infected a limited number of Mac systems through a vulnerability in the Java plug-in for browsers," the statement said.
"The malware was employed in an attack against Apple and other companies, and was spread through a website for software developers."
"We identified a small number of systems within Apple that were infected and isolated them from our network. There is no evidence that any data left Apple," it continued.
The statement said Apple was working closely with police to find the culprits, but the spokesman would not elaborate.
Apple will release a piece of software later, which it said customers can use to identify and repair Macs infected with the malware used in the attacks.
More From Sky News