Heparin is a naturally occurring anticoagulant produced by basophils and mast cells, particularly abundant in tissues around blood vessels. It works by enhancing the activity of antithrombin, a protein that inactivates thrombin and other clotting factors, thereby preventing unnecessary blood clotting in undamaged vessels.