It was at Calvi, Corsica in 1794.
The spray of stones and sand from a nearby sandbag hit by a cannonball caught his eye. He didn’t actually lose the eye; he could still distinguish between light and dark, but he lost clear vision in that eye. It was apparently a myth that he always wore an eye patch. He may have done so temporarily.
Nelson also had a scare at the battle of the Nile in 1798. He was on the quarter-deck of HMS Vanguard when he was hit on the forehead by a piece of shot which opened a flap of skin that covered his good eye, leaving him blinded and stunned. Luckily the wound wasn’t life-threatening and he was bandaged up.
* If you have come directly to this page via a search, it was actually written as a follow-up to my post: Where Nelson lost his arm at the Battle of Santa Cruz de Tenerife
(Nelson Print by Bowyer, Robert, Worthington, William Henry & Bromley, William, 1808 – National Maritime Museum, London. Public Domain)