Rio Ferdinand's late winner ensured Alex Ferguson's final match in charge at Old Trafford ended in victory for Manchester United.
The Premier League champions put in an impressive display in the first half and led thanks to Javier Hernandez, but Swansea were immensely improved after half-time and a Michu strike looked to have secured a point for the visitors, only for Ferdinand to hit an 87th-minute winner.
Given United's record under Ferguson of scoring late goals that decide crucial games, it was a fitting way for the Scot to bow out on home soil.
Ferguson's side included seven changes to the team that lost 1-0 to Chelsea last weekend as Paul Scholes started his final match at Old Trafford before he joins his manager in retirement, but the biggest surprise of all was Wayne Rooney's exclusion from the United squad. Michael Laudrup made five changes from the win over Wigan in midweek.
The home side came close to opening the scoring inside the first five minutes as Robin van Persie played Hernandez into the penalty area and the Mexican hit a left-footed shot on to the crossbar, while he had a header deflected wide by Chico Flores 10 minutes later.
United dominated the early proceedings as Hernandez, Van Persie and Shinji Kagawa linked up effortlessly, but at the other end of the pitch the interchanging between Pablo Hernandez, Nathan Dyer and Wayne Routledge proved less effective as David De Gea remained untested.
The lack of attacking problems being posed by Swansea meant Patrice Evra was able to get himself into the visitors' penalty area on numerous occasions, and after out-muscling Dwight Tiendalli on the left side of the box, he managed to get a shot on target, but Gerhard Tremmel saved the Frenchman’s tame effort at the near post.
Ferguson’s team continued to be the only side that looked like scoring and they should have been awarded a penalty for a foul on Kagawa, but, with six minutes left of the first half, the ball broke kindly for Hernandez in the area after Ashley Williams’ failed clearance and he placed the ball under Tremmel to give United the lead.
Swansea began the second half with significantly more attacking intent and after United failed to clear a corner, Michu equalised in the 49th minute as he beat Phil Jones to Dyer's right-wing cross and directed it past De Gea with the outside of his left foot.
United's awful start to the half almost got even worse three minutes later as Routledge exchanged quick passes with Michu, outpaced Ferdinand and burst into the penalty area, but he poked a shot just wide of De Gea's left-hand post.
The home side looked to have improved defensively following the poor start to the second period, but around the hour mark Pablo should have doubled Swansea’s lead as he beat Nemanja Vidic twice in the area before shooting, but De Gea made the save at the near post.
With time running out, Anderson and Antonio Valencia came on for the champions just prior to the 70th minute and the Brazilian midfielder went close to having an immediate impact as he smashed a volley a few inches wide of Tremmel's left post.
As the match entered the final 10 minutes, a Swansea winner looked increasingly likely, but when a Van Persie corner cleared everyone in the visitors' penalty area, Ferdinand held his nerve and hammered a half-volley into the top of the net from six yards out, gifting Ferguson the perfect way to end his tenure at Old Trafford.