Gillingham ended up with nine men but held on to end Oxford United's eight-game unbeaten run.
The U's dominated but Lewis Montrose scored from 25 yards out on the stroke of half-time after Ryan Clarke saved Jo Kuffour's effort.
Joe Martin was sent off for a second booking early in the second half and Montrose was shown a late red for fouling U's substitute Asa Hall.
Alfie Potter and James Constable missed late chances to level for the visitors.
Potter shot straight at Ross Flitney and Constable's injury-time chip went wide.
The results lifts Gillingham up into fifth and above Oxford, who drop to seventh in the table.
VIEWS FROM THE DRESSING ROOM
Gillingham manager Andy Hessenthaler told BBC Radio Kent:
"I'm very proud of my players. Going down to 10 men was always going to be difficult but today hopefully showed our fans what the team is all about.
"I ask the players to wear the shirt with pride and give everything they can for the football club and I thought we were outstanding.
"I thought Lewis Montrose was outstanding second half, unfortunately he's got sent off, rash challenge, young boy.
"I'm not going to be harsh on the lad because he's a fantastic player and he's won the game for us."
Oxford United boss Chris Wilder told BBC Oxford:
"Results are decided in the final third and yet again we've missed some fantastic chances.
"We just needed to be a bit more patient. We tried to force it a bit in the second half.
"It's a little like a broken record but I know we're on the right tracks. We're a decent side."