ISTANBUL — A trim and well-dressed man, dapper in a black suit, flashes a badge to enter the most genteel of events — an exhibition of photographs — pulls out a pistol and guns down an ambassador, right in the middle of the diplomatic quarter of the Turkish capital, Ankara.

Around the same time, in the shadow of a great church in Berlin that still bears the scars of bombs from World War II, a man plows a truck through a Christmas market, killing a dozen people.

The two terrorist attacks — one in Europe, the other on the periphery of Europe — came within hours of each other Monday night, bookends to a terrible year that saw the wars of the Middle East metastasize across Europe and beyond, spawning terrorism, upending the lives of ordinary citizens and energizing right-wing political movements.

The attacks could not have been more different in style, but each showed, in simultaneous fashion, the modern era of terrorism brought on by the expanding blowback of the wars in the Middle East, which have defied international efforts to end them.