Resuming on 153-8, with a lead of only 44, Elgar extended his partnership for the ninth wicket with Jack Leach to 96.
He put on 37 for the last wicket with Tim Groenewald (20) to help Somerset reach 278 and finish 113 not out.
But Alex Davies and Liam Livingstone steered Lancs to the close on 152-2.
Despite losing Haseeb Hameed cheaply again, the first of two quick wickets for Lewis Gregory as the England opener added just 7 to two successive ducks, the hosts recovered well from 23-2.
Having so far added 129 for the third wicket with Davies (78 not out), stand-in skipper Livingstone's second half-century of the match (57 not out) has helped his side close to within 17 runs of Somerset, going into day three.
Elgar's earlier effort on a sun-kissed day in Manchester was a commendable first century in England, as he carried his bat.
He passed 10,000 first-class runs when he had reached 71, although showing few variations as he hit just 11 fours in an innings of six hours and 18 minutes,
Lancashire have only lost once in their last 18 meetings with Somerset, who are unbeaten in their last nine away matches -  but, with two days still to see out, one of those sequences is likely to come to an end.
Lancashire's Ryan McLaren told BBC Radio Manchester:
"The sun seems to have baked the wicket a bit. It is definitely still doing something, but a bit slower than on day one. And we've had to claw ourselves back.
"We are still trying to get ourselves into a winning position, and that will depend on how we bat but I've been impressed by the mindset and the ambition of the team.
"The set-up at the club is unbelievable - from a player's point of view in terms of preparation, rehab, recovery - I don't think you can get much better."
Somerset's Dean Elgar told BBC Radio Somerset:
"This is my best contribution for Somerset. It was good to get runs in tough conditions. We were in trouble and the Lancashire attack exploited the conditions well.
"It required a very good game plan and it was one of those situations when, if you played and missed, you had to dust yourself off and concentrate on the next ball.
"Jack Leach played well but he has the potential to do so. He's a decent batter who has been working hard at his game."
Lancashire rallied well in the final session after a disciplined century from Somerset's South African Test player Dean Elgar had carved a 169-run first innings lead at Old Trafford.