The newspaper said it had been unaware of Mr Barkley’s heritage and there was “never any slur intended”.
The 23-year-old footballer’s grandfather was born in Nigeria.
The Sun said it had been contacted by Mr Barkley’s lawyers, who had made a formal complaint about the piece.
In the article, published on 14 April, Mr MacKenzie said looking at Mr Barkley’s eyes had given him a “similar feeling when seeing a gorilla at the zoo”.
His eyes made him “certain not only are the lights not on, there is definitely nobody at home”, he wrote.
Alongside the article, was an image of a gorilla next to a picture of the midfielder.
The columnist is currently suspended by the newspaper.
The Sun’s apology, printed on page five of the paper, said that as soon as Mr Barkley’s background was drawn to its attention, the article was removed from online.
The apology did not extend to other elements of the article, in which Mr MacKenzie suggested that the only people in Liverpool who could earn as much as footballers were drug dealers.
On Friday, Liverpool mayor Joe Anderson said Mr McKenzie would be facing questions from the police about the article.
Mr Anderson described it as a “racial slur… and something we won’t tolerate”.
A spokesman for Merseyside Police said its investigation was ongoing and officers would be speaking to relevant witnesses.
Mr MacKenzie was approached for a comment but is on holiday, although previously he has said it is “beyond parody” to describe his column as racist.
The Sun, which has previously apologised for the “wrong” and “unfunny” views of Mr MacKenzie expressed in the column, has said he will be “fully investigated” on his return.
The Sun apology in full:
“On April 14 we published a piece in the Kelvin MacKenzie column about footballer Ross Barkley which made unfavourable comparisons between Mr Barkley and a gorilla.
“At the time of publication, the newspaper was unaware of Mr Barkley’s heritage and there was never any slur intended.
“As soon as his background was drawn to our attention, the article was removed from online.
“We have been contacted by lawyers on behalf of Ross Barkley, who has made a formal complaint about the piece.
“The Sun has apologised for the offence caused by the piece.
“We would like to take this opportunity to apologise personally to Ross Barkley.”