Try this:
$post = get_post(); // If $post is already available, skip.
$terms = get_the_terms( $post->ID, 'category' );
foreach ( $terms as $term ) :
if ( $term->parent === 0 ) :
echo '<a href="' . esc_url( get_term_link( $term->term_id, 'category' ) ) .
'" title="' . esc_html( $term->name ) . '" ' . '>' . esc_html( $term->name ) .
'</a> ';
endif;
endforeach;