He died in Hawaii’s Kealakekua Bay.

Here is some information about how it happened:

It was just the wrong place and at the wrong time for Captain James Cook. It was suspected that the Hawaiians attached religious significance to the first stay of the Europeans on their islands, but no one was sure. So Cook wasn't afraid to visit Hawaiians the second time. At the time of his arrival the locals were engaged in a festival dedicated to Lono, their god of fertility. Hawaiians took Cook and his crew for gods, so they lived well among the locals for a month. But then suddenly one of the crewmen died, and the relations with the tribe became strained, as Cook and his men weren't considered immortals anymore.

Captain decided to leave and on the 4th of February, 1779, the British ships sailed from Kealakekua Bay. But they Cook and the crew weren't able to escape, as rough seas damaged the foremast of the Resolution, and after only a week at sea the expedition was forced to return to Hawaii.

The locals greeted them by hurling rocks! It was a great mess, and one of the Hawaiian chief was shot to death and a mob of Hawaiians descended on Cook’s party. The captain and his men fired on the angry Hawaiians, but they were soon overwhelmed, and only a few managed to escape to the safety of the Resolution. Captain Cook himself was killed by the mob. A few days later, the Englishmen retaliated by firing their cannons and muskets at the shore, killing some 30 Hawaiians. The Resolution and Discovery eventually returned to England.

More Info: www.history.com