It was a gesture of enormous generosity — and it came from a mystery man 8,000 miles away.

An anonymous entrepreneur from Hong Kong on Friday donated $1 million to the families of slain cops Wenjian Liu and Rafael Ramos.

“In every tragedy, there are individuals who step forward and step up to the plate, and that’s what this story is all about here today,” said Michael Palladino, president of the NYPD’s detectives union during a ceremony at union headquarters.

Liu’s father, Wei Tang Liu, will get $100,000 a year for five years under an agreement facilitated by the Sing Tao Newspaper company, while the other $500,000 will go to an education fund for Ramos’ children.

The cops’ relatives were each presented with an oversized ceremonial check for $1 million.

Ramos’ widow, Maritza, gripped her two teen sons’ hands during the event.

Rafael Ramos and Wenjian LiuGetty Images

Neither she nor Liu’s widow, Pei Xia Chen, spoke. But Liu’s father, speaking Chinese, later thanked the NYPD and all who supported the families.

Sing Tao CEO Robin Mui said the donor had been moved by the families’ plight.

“He’s just a wealthy entrepreneur in Hong Kong who doesn’t want his name to be published,” Mui said.

Meanwhile, active and retired cops will be partying on Staten Island at a benefit for the families Saturday. It starts at 7 p.m. at the Fast Break Basketball Center and will feature live bands and hot dogs. Tickets are $40 a head.