It seemed the three-time champions were set for a comfortable evening when Thomas Mueller capped a period of dominance with a straightforward finish after Fernando Muslera spilled a long-range drive from Bastian Schweinsteiger.
Uruguay forced their way back into proceedings through Edinson Cavani before Diego Forlan put them ahead with an acrobatic volley shortly after half-time.
But more poor goalkeeping from Muslera allowed Marcell Jansen to equalise and Khedira then capitalised on Uruguay’s failure to clear a Mesut Ozil corner to ensure Germany would end their tournament on a happy note.
The third-place play-off is often billed as a match that no team wants to play – but this encounter made a mockery of any such suggestion.
Uruguay exceeded all expectations in reaching the last four and, with a parade through the streets of Montevideo and a date with President Jose Mujica planned for Monday, they were desperate to finish their campaign on a high.
Germany, meanwhile, are a hugely talented young squad who will be together for some years and viewed the meeting with La Celeste as another stepping stone in their development.
Oscar Tabarez’s men signalled their intent by restoring fit-again captain Diego Lugano and star striker Luis Suarez, suspended for the last-four defeat by the Netherlands, to the starting line-up.
Although Germany made five changes from the side beaten by Spain, Philipp Lahm and Lukas Podolski were suffering from a virus, Miroslav Klose had a bad back and coach Joachim Loew was still able to name an enviable line-up.
And it was clear from the opening exchanges that this was no friendly as Mueller saw a strike ruled out for handball, Dennis Aogo escaped with a caution for a terrible studs-up challenge on Diego Perez and Forlan curled a free-kick just over.
Germany, however, dominated the early possession and, after Arne Friedrich had nodded a Ozil corner against the crossbar, they opened the scoring.
Schweinsteiger unleashed a swerving drive from about 35 yards that was spilled by Muslera, offering Mueller a simple finish to draw level with David Villa and Wesley Sneijder on five goals.
Germany might have been expected to kick on from there but instead they sat back on their lead and invited Uruguay forward, while looking to launch the occasional counter-attack of their own.
The two-time champions duly settled into a tidy rhythm, showcasing their ability to turn defence into attack at frightening pace, and were soon back on level terms.
Schweinsteiger, captaining Germany in the absence of Lahm, was robbed of possession by Perez before Forlan fed Cavani and the 23-year-old Palermo striker calmly slotted past Hans Joerg Butt.
Despite persistent rainfall at the Nelson Mandela Bay Stadium, Uruguay were passing and moving beautifully and they should have gone ahead before the break when Forlan released Suarez, only for the Ajax frontman to drag a shot wide.
Germany, making a record fifth appearance in the third-place play-off, seemed to have lost their earlier intensity and that allowed the South Americans, full of desire and no shortage of quality, to pick up where they left off in the second period.
Forlan, Suarez and Cavani caused their opponents all manner of problems and, after Cavani and Suarez were denied by Butt, Forlan met Egidio Arevalo’s cross with a superb volley to notch his fifth goal of the finals.
Uruguay deserved their advantage and, with Germany showing little potency in the final third, they looked set fair for a fine victory.
But Muslera’s unconvincing attempt at claiming a Jerome Boateng cross allowed Jansen to divert the ball into an unguarded net and suddenly the momentum had shifted.
Uruguay, who have still not beaten a European team at the World Cup since 1970, rapidly began to tire and Germany substitute Stefan Kiessling twice squandered opportunities to grab the winner before Khedira made no mistake.
Tabarez’s players refused to accept defeat and almost forced extra time, Forlan curled a 92nd-minute free-kick on to the bar.
But Germany held on and their celebrations at full-time showed exactly what this result meant to them.