Chasing 311, Australia struggled at 231-9 before its last-wicket pair of Brad Haddin (71) and James Pattinson (25 not out) took the total to 296 and the brink of a famous victory.
"It's pretty tough to be honest after getting so close," Australia captain Michael Clarke said. "But first of all credit has to go to England. I think our boys should hold their heads high."
Haddin was given out caught behind after a referral revealed he had got the faintest inside edge to man-of-the-match Anderson in the third over after lunch.
"Australia fought incredibly hard, but we just hung in there," England captain Alastair Cook said. "Jimmy was outstanding. He always wants one more over, 13 was quite a lot. He's a world-class bowler and sometimes you just use him. It happened to be Jimmy's day and Jimmy's game."
England leads the five test series 1-0. The second test starts at Lord's on Thursday.
Anderson had earlier taken three wickets during the morning session.
However, Haddin and Pattinson put on 65 for the final wicket and were close to breaking the record for a last-wicket pair to win a test match — set by Inzamam-ul-Haq and Mushtaq Ahmed, who made 57 for Pakistan vs. Australia in 1994.
Play began with the floodlights on to combat the overcast conditions and the first runs of the morning came when Haddin flashed Anderson through third slip for four in the second over of the session.
England opted not to take the new ball until the 82nd over and Australia took this as a cue to attack.
Haddin cut Anderson through extra cover for four to take the tourists past 200, prompting England captain Cook to set more defensive fields.
Agar (14) offered few chances, but he finally fell after 57 minutes when he nudged Anderson to first slip.
Mitchell Starc then fell in almost identical fashion, lasting just five balls before he was tempted by Anderson and caught by Cook for 1.
Peter Siddle reduced the target to less than 100 with successive boundaries off Broad and was dropped by Cook off Anderson when he was on 10.
Cook atoned brilliantly in Anderson's next over with a superb diving catch.
Anderson bowled for nearly two hours from the Radcliffe Road End but, when he was replaced, Haddin smashed Steven Finn for three consecutive boundaries.
The lunch session was extended as England chased the final wicket, but Finn bowled two overs for 24 runs and Pattinson hit Swann for six over midwicket to reduce the target to 31.
Haddin was nearly run out on 62 but Jonny Bairstow's throw was easily wide and Finn's wretched morning continued when Haddin lofted Swann to the square leg boundary and he dropped a difficult chance, spilling the ball for four runs.
The lunch interval gave Anderson the chance to recover and in his second over of the session Haddin swished at the fifth ball.
Haddin was initially given not out by Aleem Dar but England referred the call. The hotspot camera revealed an almost imperceptible edge and the tourists' run chase was thwarted in the most agonizing fashion.
Anderson wasn't even certain that Haddin was out.
"I didn't hear anything and I wasn't sure to be honest," he said. "I thought it might have been one of those where the wind was blowing."
Cook had no doubts, however.
"Matt Prior and I were 99.9 per cent certain he'd nicked it," he said. "We heard the edge."Suggest a correction