Yes there is an ambiguity in a, b. I'd usually understand them to mean not twice but once. Context would help:
The party endorsed him in 1824 but refused to endorse him twice...
Also, in speech, stress would clarify
The party didn't endorse him on two occasions.
And you are right that the a1, b1 seem have the other meaning: there were two occasions on which the party could have endorsed him, but didn't.
In many contexts not doing something multiple times can produce some weird, even comical meanings. Alice (through the looking glass) wonders if she could save up her punishments of "going without dinner" until the end of the year.
I should have to go without fifty dinners at once! Well, I shouldn’t mind that much! I’d far rather go without them than eat them!
So the idea of "On two occasions it didn't do something" implies that there were two occasions on which "something" could have occurred. This is a slightly odd sense, and there are probably clear ways to express yourself:
The candidate ran for President twice, but on neither occasion did the party endorse him.