The present invention provides compounds that inhibit Factor XIa and methods of preventing or treating undesired thrombosis by administering a compound of the invention to a mammal. The invention also provides three-dimensional structures of Factor XIa and methods for designing or selecting additional Factor XIa inhibitors using these structures.