By naming Russian mobilisation as the initial aggression.
One needs to look no further than the German declaration of war itself. That document succinctly laid out Berlin's position that the Russian mobilisation was an existential threat as well as an act of aggression towards Germany. Presenting Germany as a peaceful mediator, it claims that:
[Russia] proceeded to a general mobilisation of her forces both on land and sea. In consequence of this threatening step ... the German Empire was faced by a grave and imminent danger. If the German Government had failed to guard against this peril, they would have compromised the safety and the very existence of Germany. The German Government [therefore insisted] upon a cessation of the aforesaid military acts. Russia having refused to comply [have shown] that her action was directed against Germany
The document ended by explicitly portraying the Germany as answering a challenge to fight. A challenge which, according to the German government, Imperial Russia had issued by mobilising.
His Majesty the Emperor, my august Sovereign, in the name of the German Empire, accepts the challenge, and considers himself at war with Russia.
Germany thus portrayed herself as a victim of Russian aggression, and her subsequent military actions "self-defence".
The German argument was not a stretch to make in 1914. Countries did not (and do not) mobilise for fun. In an age of mass conscript armies, mobilisation was the key stage in the ramp up to war. The tight coupling of mobilisation with war was such that it was effectively regarded as an act of war in and of itself. In Russia specifically,
The idea that mobilization was not a peaceful act but 'the most decisive act of war' had been present in the thought of Russian officers since 1892. The 1912 the European military districts were told to regard mobilization as the opening of hostilities.
- Strachan, Hew. The Outbreak of the First World War. Oxford University Press, 2004.
Moreover, Russia was allied to France by an accord that was understood, by both sides, to mean that mobilisation guaranteed a war on two fronts for Germany.
General N. N. Obruchev, Russia's signatory, explained [Article 2 to mean], 'this mobilisation of France and Russia would be followed immediately by positive results, by acts of war, in a word would be inseparable from an "aggression"'. Or as France's counterpart to Obruchev, General Raoul de Boisdeffre, put it after signing the accord, "the mobilization is the declaration of war."
- McMeekin, Sean. July 1914: Countdown to War. Basic Books, 2014.
In the mindset of 1914 Europe, therefore, the Russian mobilisation essentially meant war. This also meant that the German ultimatum for Russia to cease its mobilisation would not have detracted from the self defence argument. If anything, it strengthened it - Germany could present itself as having explored all changes for peace before before "accepting" the Russian challenge to fight.
Disclaimer: Whether the German rationale is objectively correct is of course an entirely different matter. This answer also no commentary on the (in)accuracy of the other Great Powers' claims for a righteous casus beli, either.