A three-hour shootout between Mexican security forces and unidentified gunmen Friday left 42 of the gunmen dead, as well as one federal police officer, officials said.