Ms. Shaheen, a biotech entrepreneur and former city councilor, fended off a rival who attacked her family connections.