Harlequins edged a see-saw encounter against Gloucester to record their first win in three Premiership matches.
The Cherry and Whites led 12-10 at the break as Ollie Thorley scored either side of Ross Chisholm's try for Quins.
A Marcus Smith penalty put Quins ahead but Ben Morgan powered over for the visitors and Danny Cipriani converted.
Alex Dombrandt crashed over and Smith converted to give Quins a one-point lead and, after Gloucester missed a penalty, Smith's late kick settled it.
Both sides had lost their past two league games coming into the meeting at The Twickenham Stoop - and the match proved to be close, with the lead changed hands six times over the course of the 80 minutes once Smith's early penalty put Paul Gustard's side in front.
With Quins 20-19 ahead with nine minutes remaining Gloucester could have snatched the lead back but Billy Twelvetrees sliced his penalty attempt wide of the sticks from just outside the 22, with the centre under time pressure to take his kick having had to replace the ball on the tee.
Harlequins showed good game management to close out the contest and register their second league win of the campaign, moving them up to eighth in the table and three points off the top four.
The hosts were due to welcome back England international Kyle Sinckler following his efforts at the World Cup but the prop, who was initially named on the bench, dropped out with injury on Sunday morning.
Harlequins: R Chisholm; Ismaiel, Campagnaro, Lang, Ibitoye; Smith, Care; Marler, Elia, Collier, Lewies, Symons, Lawday, Robshaw (capt), Dombrandt.
Replacements: Musk, Auterac, Kerrod, Cavubati, Kunatani, Landajo, Saili, Lasike.
Gloucester: Marshall; Rees-Zammit, Harris, Atkinson, Thorley; Cipriani, Simpson; Rapava-Ruskin, Marais, Ford-Robinson, Craig, Mostert, Ackermann, Ludlow, Morgan (capt).
Replacements: Gleave, Hohneck, Balmain, Clarke, Polledri, Braley, Twelvetrees, Banahan.
Referee: Craig Maxwell-Keys.